中国最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2

xmldom教程

XML DOM removeAttributeNode() 方法——Element 对象

阅读 (1790)

XML DOM removeAttributeNode() 方法


Element 对象参考手册 Element 对象

定义和用法

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++)
{
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 对象参考手册 Element 对象
关闭
程序员人生