XML DOM removeAttribute() 方法
Element 對(duì)象
定義和用法
removeAttribute() 方法刪除指定的屬性。
如果屬性的默認(rèn)值是在 DTD 中定義,那么新屬性出現(xiàn)時(shí)會(huì)帶有該默認(rèn)值。
語(yǔ)法
elementNode.removeAttribute(name)
參數(shù) | 描述 |
name | 必需。規(guī)定要?jiǎng)h除的屬性。 |
實(shí)例
下面的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,并刪除所有 <book> 元素的 "category" 屬性:
實(shí)例
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 對(duì)象