คุณสมบัติความยาว XML DOM
❮ วัตถุ NamedNodeMap
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " books.xml " ลงใน xmlDoc และรับจำนวนแอตทริบิวต์ในองค์ประกอบ <book> แรก:
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("book");
document.getElementById("demo").innerHTML =
"Number of
attributes in the first book element: " +
x.item(0).attributes.length;
}
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Number of attributes in the first book element:
1
ความหมายและการใช้งาน
คุณสมบัติ length ส่งกลับจำนวนโหนดใน NamedNodeMap
ไวยากรณ์
nodemapObject.length
ทดลองด้วยตัวเอง
❮ วัตถุ NamedNodeMap