DOM

参考自维基及MDN

介绍

DOM全称为Document Object Model, 其是一个跨平台的HTML类的API (Application Programming Interface),其将HTML, XHTML, XML等文件定义为树结构,每个节点Node是代表文件一部分内容的Object, 这些Object可以被编程操控,并且对其的修改可能会影响文件的显示。

历史

DOM产生于1990后期,同时也是浏览器大战时期,Netscape发布了应用JavaScript引擎的Web浏览器,以及脚本语言JavaScript,微软则推出IE及JScript。JS的出现使web开发者能创建在客户端能交互的页面。其中用于检测用户的活动以及对HTML页面的修改的工具被称为DOM Level 0, 但还未由统一的标准。

在ECMAScript标准化后,W3C则着手制定DOM的标准化,后续则由WHATWG接收标准的发展,W3C则发布WHATWG标准中稳定的版本。

  • DOM Level 1 provided a complete model for an entire HTML or XML document, including the means to change any portion of the document.

  • DOM Level 2 was published in late 2000. It introduced the getElementById function as well as an event model and support for XML namespaces and CSS.

  • DOM Level 3, published in April 2004, added support for XPath and keyboard event handling, as well as an interface for serializing documents as XML.

  • DOM Level 4 was published in 2015. It is a snapshot of the WHATWG living standard.[7]

应用

DOM示意:


DOM_第1张图片
DOM

浏览器将在加载页面的时候生成DOM,我们可以通过JS与DOM进行交互:

  1. 在DOM中修改或移除HTML元素。
  2. 修改或添加元素的CSS样式。
  3. 读取或修改元素的属性,如href,src,alt,custom。
  4. 创建新的HTML元素,并把它们插入到DOM或页面里。
  5. 对元素附加事情监听,如click, keypress, submit等。

DOM最新版本可从WHATWG中查看

JavaScript与DOM可参考以下书籍及视频:
JavaScript DOM编程艺术
Youtube视频

你可能感兴趣的:(DOM)