DOM(Document Object Model)文檔對象模型,將網(wǎng)頁轉(zhuǎn)為一個JS對象,從而用腳本進(jìn)行各種操作。
七種節(jié)點(diǎn)類型:
-
Document:,文檔樹的頂層節(jié)點(diǎn) -
DocumentType:doctype標(biāo)簽 -
Element:各種HTML標(biāo)簽 -
Attribute:網(wǎng)頁元素的屬性 -
Text:標(biāo)簽之間或標(biāo)簽包含的文本 -
Comment:注釋 -
DocumentFragment:文檔的片段
瀏覽器提供一個原生的節(jié)點(diǎn)對象Node,具有共同的屬性和方法。
節(jié)點(diǎn)樹中各節(jié)點(diǎn)的關(guān)系:
- 父節(jié)點(diǎn)關(guān)系
- 子節(jié)點(diǎn)關(guān)系
- 同級節(jié)點(diǎn)關(guān)系
Node接口
DOM操作的基礎(chǔ)是Node。
nodeType屬性,表示節(jié)點(diǎn)的類型
document.nodeType //9
不同節(jié)點(diǎn)的nodeType屬性值和對應(yīng)的常量如下:
- document:9, 對應(yīng)常量
Node.DOCUMENT_NODE - element:1, 對應(yīng)常量
Node.ELEMENT_NODE - attr:2, 對應(yīng)常量
Node.ATTRIBUTE_NODE - text:3, 對應(yīng)常量
Node.TEXT_NODE - DocumentFragment:11, 對應(yīng)常量
Node.DOCUMENT_FRAGMENT_NODE - DocumentType:10,對應(yīng)常量
Node.DOCUMENT_TYPE_NODE - Comment:8,對應(yīng)常量
Node.COMMENT_NODE
文檔節(jié)點(diǎn):
- nodeName:#document
- nodeValue:null
元素節(jié)點(diǎn):
- nodeName:大寫的標(biāo)簽名
- nodeValue:null
屬性節(jié)點(diǎn):
- nodeName:屬性的名稱
- nodeValue:null
文本節(jié)點(diǎn):
- nodeName:#text
- nodeValue:文本內(nèi)容
文檔片段節(jié)點(diǎn):
- nodeName:#document-fragment
- nodeValue:null
文檔類型節(jié)點(diǎn):
- nodeName:文檔的類型
- nodeValue:null
注釋節(jié)點(diǎn):
- nodeName:#comment
- nodeValue:文本內(nèi)容
未完待續(xù)。。。