What is the DOM?
With JavaScript you can restructure an entire HTML document. You can add, remove, change, or reorder items on a page.
To change anything on a page, JavaScript needs access to all elements in the HTML document. This access, along with methods and properties to add, move, change, or remove HTML elements, is given through the Document Object Model (DOM).
In 1998, W3C published the Level 1 DOM specification. This specification allowed access to and manipulation of every single element in an HTML page.
All browsers have implemented this recommendation, and therefore, incompatibility problems in the DOM have almost disappeared.
The DOM can be used by JavaScript to read and change HTML, XHTML, and XML documents.
The DOM is separated into different parts (Core, XML, and HTML) and different levels (DOM Level 1/2/3):
Core DOM - defines a standard set of objects for any structured document XML DOM - defines a standard set of objects for XML documents HTML DOM - defines a standard set of objects for HTML documents
Everything in an HTML document is a node.
Nodes
According to the DOM, everything in an HTML document is a node.
The DOM says that:
The entire document is a document node Every HTML tag is an element node The texts contained in the HTML elements are text nodes Every HTML attribute is an attribute node Comments are comment nodesNode Hierarchy
Nodes have a hierarchical relationship to each other.
All nodes in an HTML document form a document tree (or node tree). The tree starts at the document node and continues to branch out until it has reached all text nodes at the lowest level of the tree.
The following figure represents a document tree (node tree):

本文介绍了DOM(文档对象模型)的基本概念及其在JavaScript中如何用于操作HTML文档。从W3C发布DOM Level 1标准开始,浏览器实现了对DOM推荐标准的支持,减少了浏览器间的不兼容问题。DOM不仅适用于HTML,也适用于XML和XHTML文档。
2856

被折叠的 条评论
为什么被折叠?



