SHARE
TWEET

Untitled

a guest Feb 15th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```language
  2. HTML DOM (文档对象模型)
  3. 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model)。
  4.  
  5. HTML DOM 模型被构造为对象的树。
  6.  
  7. HTML DOM 树
  8. ![ct_htmltree.gif](data:image/gif;base64,R0lGODlh5gEKAaIAAP////8AAJmZmQAA/wAAAAAAAAAAAAAAACH5BAAHAP8ALAAAAADmAQoBAAP/CLrc/jDKSau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wrGBOr9vv+Lx+z+/7/3GBgkd/hYaHiIl3g4yNPnNtkI6TlDSSa5eVmpspmWmenKGiHqBnpaOoqROnZayqr7CuY7KwtaK0Ybi2u5S6IwQRwAvCMr68x4LGIsTEAMDC0DHKyNSRAi0E2drbz9rO380u09XkaOMdzA7R2TPn5e9i7hvpDd3c0tfw+nHyGvTD7Orh20fQTT9/3xg8exCOxcGCEKU8xLBQIThuDVdMjMiR/8nGCxkTCoTxsaNJIyUnsAtoUd3AkzC7pGTIUoE3m84wvozJE8tMJz97CrUR1GO+oUihFF2yNKlTjUfVNH1K1cRUJFeragWRFWXUrWAffTU3NqxZHF2LpD3LNsLaIW/byl2gqK7du4nm6i2Gt6/fv3H3Cq4RcrDhY4UPK4aVeLHjUY0fS9YUebLlRpUva46TebNnNp0/iz4TerRpMaVPq+6SerVrLK1fy54Se7ZtJ7Vv606Se7dvIr1/C/8RfLhxHcWPKye8vLmS5M6js4AuvfoJ6tZPY9zOvbv37+DDix+f/Sx2KefLk0sPhb16ZOyhbZMQ0j3992Dj49yfcztA//8u2IefLefNdw9CwaQn4ICMoRANfyp5V4+CDFal4IMJfTfSgiNV6NSF9tSUIU0QBujhUwWOiOGIEATE4TAnfmhCRQuFs+J/BypEYYxI6cdiS/+AI9KE1/HYo4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kyk5NWkhXpPhIpj9jViUfFkW7YkcDjZH0CVzFFhf1rtwA2mYM7BEAFtZSRGI/Q1pBI+UBKaVu86I2xJo81uZVkEJUpuI5aKZX9eJbwYJZGYJJiIHhXN5d0WZc9t3R2mZd66XRTt5d++ZdD50iCOZiEWZiGeZiImZiKuZiM2ZiO+ZiQGZmSOZljkAAAOw==)
  9. DOM HTML 树
  10. 通过可编程的对象模型,JavaScript 获得了足够的能力来创建动态的 HTML。
  11.  
  12. JavaScript 能够改变页面中的所有 HTML 元素
  13. JavaScript 能够改变页面中的所有 HTML 属性
  14. JavaScript 能够改变页面中的所有 CSS 样式
  15. JavaScript 能够对页面中的所有事件做出反应
  16. 查找 HTML 元素
  17. 通常,通过 JavaScript,您需要操作 HTML 元素。
  18.  
  19. 为了做到这件事情,您必须首先找到该元素。有三种方法来做这件事:
  20.  
  21. 通过 id 找到 HTML 元素
  22. 通过标签名找到 HTML 元素
  23. 通过类名找到 HTML 元素
  24. 通过 id 查找 HTML 元素
  25. 在 DOM 中查找 HTML 元素的最简单的方法,是通过使用元素的 id。
  26.  
  27. 实例
  28. 本例查找 id="intro" 元素:
  29.  
  30. var x=document.getElementById("intro");
  31. 如果找到该元素,则该方法将以对象(在 x 中)的形式返回该元素。
  32.  
  33. 如果未找到该元素,则 x 将包含 null。
  34.  
  35. 通过标签名查找 HTML 元素
  36. 实例
  37. 本例查找 id="main" 的元素,然后查找 "main" 中的所有 <p> 元素:
  38.  
  39. var x=document.getElementById("main");
  40. var y=x.getElementsByTagName("p");
  41. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top