XML DOM hasAttributeNS()เมธอด
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้จะโหลด " books_ns.xml " ลงใน xmlDoc และตรวจสอบว่าองค์ประกอบ <title> แรกมีแอตทริบิวต์ใดๆ ของเนมสเปซและชื่อที่ระบุหรือไม่:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName("title")[0];
var ns = "https://www.w3schools.com/children/";
document.getElementById("demo").innerHTML =
x.hasAttributeNS(ns,"lang");
}
เอาท์พุท:
true
ความหมายและการใช้งาน
hasAttributeNS() วิธีการส่งกลับ TRUE ถ้าโหนดองค์ประกอบปัจจุบันมีแอตทริบิวต์ที่ระบุโดยเนมสเปซและชื่อ และ FALSE มิฉะนั้น
ไวยากรณ์
hasAttributeNS(ns,name)
Parameter | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to find |
name | Required. Specifies the name of the attribute to find |
❮ วัตถุธาตุ