XML DOM removeAttributeNS() 方法
❮ 元素物件
示例
以下程式碼片段將 "books_ns.xml" 載入到 xmlDoc 中,並移除第一個 <title> 元素的 "lang" 屬性
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 =
"Attribute Found: " + x.hasAttributeNS(ns, "lang");
x.removeAttributeNS(ns, "lang");
document.getElementById("demo").innerHTML +=
"<br>Attribute Found: " + x.hasAttributeNS(ns, "lang");
}
輸出
Attribute Found: true
Attribute Found: false
自己動手試一試 »
定義和用法
removeAttributeNS() 方法會移除由名稱空間和名稱指定的屬性。
語法
elementNode.removeAttributeNS(ns,name)
引數 | 描述 |
---|---|
ns | 必需。指定要移除的屬性的名稱空間 |
name | 必需。指定要移除的屬性名稱 |
❮ 元素物件