XML DOM removeAttributeNode() 方法
Element 對象
定義和用法
removeAttributeNode() 方法刪除指定的屬性節(jié)點。
如果屬性的默認值是在 DTD 中定義,那么新屬性出現(xiàn)時會帶有該默認值。
該函數(shù)返回要刪除的屬性節(jié)點。
語法
elementNode.removeAttributeNode(node)
參數(shù) | 描述 |
node | 必需。要刪除的節(jié)點。 |
實例
下面的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,并刪除所有 <book> 元素的 "category" 屬性節(jié)點:
實例
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 + "
");
}
輸出:
Removed attribute: category
Removed attribute: category
Removed attribute: category
Removed attribute: category
嘗試一下 ?
Element 對象
更多建議: