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() วิธีการคืนค่า TRUE หากโหนดองค์ประกอบปัจจุบันมีแอตทริบิวต์ใด ๆ และ FALSE มิฉะนั้น
ไวยากรณ์
hasAttributes()
❮ วัตถุธาตุ