XML DOM hasChildNodes() Method
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " 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')[0];
document.getElementById("demo").innerHTML =
x.hasChildNodes();
}
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
true
ความหมายและการใช้งาน
hasChildNodes() วิธีการส่งคืนค่า TRUE หากโหนดองค์ประกอบปัจจุบันมีโหนดย่อยและ FALSE มิฉะนั้น
ไวยากรณ์
elementNode.hasChildNodes()
❮ วัตถุธาตุ