XML DOM removeAttributeNode() 方法
定義和用法
removeAttributeNode() 方法從元素中刪除指定的屬性節(jié)點(diǎn)。
語法:
elementNode.removeAttributeNode(node)
參數(shù) | 描述 |
---|---|
node | 必需。要?jiǎng)h除的節(jié)點(diǎn)。 |
返回值
刪除的 Attr 節(jié)點(diǎn)。
說明
該方法從當(dāng)前元素的屬性集合中刪除(并返回)一個(gè) Attr 節(jié)點(diǎn)。如果 DTD 給刪除的屬性設(shè)置了默認(rèn)值,那么該方法將添加一個(gè)新的 Attr 節(jié)點(diǎn),表示這個(gè)默認(rèn)值。用 removeAttribute() 方法代替該方法往往會(huì)更簡單。
實(shí)例
在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數(shù) loadXMLDoc()。
下面代碼片段從 "books.xml" 中的所有 <book> 元素中刪除 "category" 屬性:
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
old_att=x.item(i).removeAttributeNode(attnode)
;
document.write("Removed attribute: " + old_att.name + "<br />");
}
輸出:
Removed attribute: category Removed attribute: category Removed attribute: category Removed attribute: category