XML DOM removeAttribute() 方法
❮ 元素物件
示例
以下程式碼片段載入 "books.xml" 到 xmlDoc 中,並移除所有 <book> 元素的 "category" 屬性
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");
document.getElementById("demo").innerHTML =
x[0].getAttribute('category') + "<br>";
x[0].removeAttribute('category');
document.getElementById("demo").innerHTML +=
x[0].getAttribute('category');
}
輸出
cooking
null
自己動手試一試 »
定義和用法
removeAttribute() 方法用於移除指定的屬性。
如果在 DTD 中定義了該屬性的預設值,那麼會立即出現一個帶有預設值的新屬性。
語法
elementNode.removeAttribute(name)
引數 | 描述 |
---|---|
name | 必需。指定要移除的屬性 |
❮ 元素物件