XML DOM removeAttributeNS() 方法

定义和用法

removeAttributeNS() 方法删除由命名空间和名称指定的属性。

语法:

elementNode.removeAttributeNS(ns,name)
参数 描述
ns 必需。规定要删除的属性的名字空间。
name 必需。规定要删除的属性的名称。

实例

在所有的例子中,我们将使用 XML 文件 books_ns.xml,以及 JavaScript 函数 loadXMLDoc()

下面的代码片段从 "books_ns.xml" 中的第一个 <title> 元素删除 "lang" 属性:

xmlDoc=loadXMLDoc("books_ns.xml");

x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.w3school.com.cn/children/";

document.write("Attribute Found: ");
document.write(x.hasAttributeNS(ns,"lang"));

x.removeAttributeNS(ns,"lang");

document.write("<br />Attribute Found: ");
document.write(x.hasAttributeNS(ns,"lang"));

输出:

Attribute Found: true
Attribute Found: false