XML DOM removeAttribute() 方法

Element 对象参考手册 Element 对象

定义和用法

removeAttribute() 方法删除指定的属性。

如果属性的默认值是在 DTD 中定义,那么新属性出现时会带有该默认值。

语法

elementNode.removeAttribute(name)

参数描述
name必需。规定要删除的属性。


实例

下面的代码片段使用 loadXMLDoc() 把 "books.xml" 载入 xmlDoc 中,并删除所有 <book> 元素的 "category" 属性:

实例

xmlDoc=loadXMLDoc("books.xml");
 
x=xmlDoc.getElementsByTagName('book');
 
document.write(x[0].getAttribute('category'));
document.write("<br>");
 
x[0].removeAttribute('category');
 
document.write(x[0].getAttribute('category'));

尝试一下 »

Element 对象参考手册 Element 对象

0 个评论

要回复文章请先登录注册