XML DOM คุณสมบัติประเภทโหนด
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " 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
Node Number: | Node Name: |
---|---|
1 | Element |
2 | Attribute |
3 | Text |
4 | CDATA Section |
5 | Entity Reference |
6 | Entity |
7 | Processing Instruction |
8 | Comment |
9 | Document |
10 | Document Type |
11 | Document Fragment |
12 | Notation |
ทดลองด้วยตัวเอง
❮ วัตถุธาตุ