XML DOM hasAttributes() 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.hasAttributes();
}
เอาท์พุท:
true
ความหมายและการใช้งาน
hasAttributes() วิธีการคืนค่าจริงหากโหนดที่ระบุมีแอตทริบิวต์ใด ๆ มิฉะนั้นfalse
หมายเหตุ:หากโหนดที่ระบุไม่ใช่โหนดองค์ประกอบ ค่าที่ส่งคืนจะเป็นfalseเสมอ
รองรับเบราว์เซอร์
hasAttributes() วิธีการได้รับการสนับสนุนในเบราว์เซอร์หลักทั้งหมด
หมายเหตุ: Internet Explorer 9 และรุ่นก่อนหน้าไม่รองรับเมธอด hasAttributes()
ไวยากรณ์
nodeObject.hasAttributes()
พารามิเตอร์
ไม่มี.
คืนมูลค่า
Type | Description |
---|---|
Boolean | Returns true if the specified node has any attributes, otherwise false |
รายละเอียดทางเทคนิค
เวอร์ชัน DOM | วัตถุโหนดหลักระดับ 2 |
---|
❮ วัตถุโหนด