XML DOM nodeType 屬性
❮ 元素物件
示例
以下程式碼片段將 "books.xml" 載入到 xmlDoc 中,並獲取第一個 <title> 元素的節點型別
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("title")[0];
document.getElementById("demo").innerHTML =
x.nodeType;
}
上面程式碼的輸出將是
1
自己動手試一試 »
定義和用法
nodeType 屬性返回所選節點的節點型別。
語法
elementNode.nodeType
節點型別 | 節點名稱 |
---|---|
1 | 元素 |
2 | Attribute |
3 | 文字 |
4 | CDATA Section |
5 | Entity Reference |
6 | 實體 |
7 | Processing Instruction |
8 | 註釋 |
9 | 文件 |
10 | Document Type |
11 | Document Fragment |
12 | Notation |
實際操作演示
❮ 元素物件