XML DOM removeAttribute() 方法
Element 對象
定義和用法
removeAttribute() 方法刪除指定的屬性。
如果屬性的默認值是在 DTD 中定義,那么新屬性出現(xiàn)時會帶有該默認值。
語法
elementNode.removeAttribute(name)
參數(shù) | 描述 |
name | 必需。規(guī)定要刪除的屬性。 |
實例
下面的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,并刪除所有 <book> 元素的 "category" 屬性:
實例
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
document.write(x[0].getAttribute('category'));
document.write("
");
x[0].removeAttribute('category');
document.write(x[0].getAttribute('category'));
嘗試一下 ?
Element 對象
更多建議: