hw07_11.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <header>
  2. <h1>Destructure</h1>
  3. </header>
  4. <body>
  5. <script>
  6. html =
  7. {
  8. "tagName": "body",
  9. "children": [
  10. {
  11. "tagname": "div",
  12. "children": [
  13. {
  14. "tagName": "span",
  15. "children": [
  16. "Enter a data please:"
  17. ],
  18. },
  19. {
  20. "tagName": "br"
  21. },
  22. {
  23. "tagName": "input",
  24. "attrs": {
  25. "type": "text",
  26. "id": "name"
  27. }
  28. },
  29. {
  30. "tagName": "input",
  31. "attrs": {
  32. "type": "text",
  33. "id": "surname"
  34. }
  35. }
  36. ]
  37. },
  38. {
  39. "tagName": "div",
  40. "children": [
  41. {
  42. "tagName": "button",
  43. "attrs": {
  44. "id": "ok"
  45. },
  46. "children": [
  47. "OK"
  48. ]
  49. },
  50. {
  51. "tagName": "button",
  52. "attrs": {
  53. "id": "cancel"
  54. },
  55. "children": [
  56. "Cancel"
  57. ]
  58. }
  59. ]
  60. }
  61. ]
  62. };
  63. const { children: [{ children: [{ children: [spanValue] }] }] } = html;
  64. const { children: [, { children: [, { children: [btnValue] }] }] } = html;
  65. const { children: [{ children: [, , , { attrs: { id } }] }] } = html;
  66. console.log(spanValue);
  67. console.log(id);
  68. console.log(btnValue)
  69. </script>
  70. </body>