TUTORIAL前端与浏览器FETCHED
XML DOM getAttributeNS() 方法
XML DOM getAttributeNS() 方法 Element 对象 定义和用法 getAttributeNS() 方法通过命名空间 URI 和名称取得属性值。 语法 elementNode.getAttributeNS(ns,name) 参数 描述 ns 必需。规定从中获取属性值的命名空间 URI。 name 必需。规定从中获取属性值的属性。 实例 下面的代..
更新于 2026/7/16
教程详情页默认 noindex。
XML DOM getAttributeNS() 方法
Element 对象
定义和用法
getAttributeNS() 方法通过命名空间 URI 和名称取得属性值。
语法
elementNode.getAttributeNS(ns,name)
| 参数 | 描述 |
|---|---|
| ns | 必需。规定从中获取属性值的命名空间 URI。 |
| name | 必需。规定从中获取属性值的属性。 |
实例
下面的代码片段使用 loadXMLDoc() 把 "books_ns.xml" 载入 xmlDoc 中,创建一个新的 <book> 节点,并从第一个 <title> 元素中取得 "lang" 属性值:
实例
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="https://www.runoob.com/w3cnote/";
document.write(x.getAttributeNS(ns,"lang"));
输出:
cn
尝试一下 »
Element 对象