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://w3schools.tw/children/";
document.getElementById("demo").innerHTML =
x.hasAttributeNS(ns,"lang");
}
輸出
true
自己動手試一試 »
定義和用法
hasAttributeNS() 方法如果當前元素節點具有由名稱空間和名稱指定的屬性,則返回 TRUE,否則返回 FALSE。
語法
hasAttributeNS(ns,name)
引數 | 描述 |
---|---|
ns | 必需。指定要查詢的屬性的名稱空間 |
name | 必需。指定要查詢的屬性的名稱 |
❮ 元素物件