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() วิธีการคืนค่าจริงหากโหนดที่ระบุมีโหนดย่อย มิฉะนั้นfalse
รองรับเบราว์เซอร์
hasChildNodes() วิธีการได้รับการสนับสนุนในเบราว์เซอร์หลักทั้งหมด
ไวยากรณ์
nodeObject.hasChildNodes()
พารามิเตอร์
ไม่มี.
คืนมูลค่า
Type | Description |
---|---|
Boolean | Returns true if the specified node has any child nodes, otherwise false |
รายละเอียดทางเทคนิค
เวอร์ชัน DOM | วัตถุโหนดหลักระดับ 1 |
---|
❮ วัตถุโหนด