XML DOM removeAttributeNode() 方法

定義和用法
removeAttributeNode() 方法刪除指定的屬性節點。
如果屬性的默認值是在 DTD 中定義,那麼新屬性出現時會帶有該默認值。
該函數返回要刪除的屬性節點。
語法
elementNode.removeAttributeNode(node)
參數 | 描述 |
---|---|
node | 必需。要刪除的節點。 |
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,並刪除所有 <book> 元素的 "category" 屬性節點:
實例
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for (i=0;i<x.length;i++)
{
while (x[i].attributes.length>0)
{
attnode=x[i].attributes[0];
old_att=x[i].removeAttributeNode(attnode);
document.write("Removed: " + old_att.nodeName)
document.write(": " + old_att.nodeValue)
document.write("<br>")
}
}
