NamedNodeMap: removeNamedItemNS() 方法
NamedNodeMap 接口的 removeNamedItemNS() 方法会从映射中移除具有给定命名空间和本地名称的 Attr 节点。
语法
js
removeNamedItemNS(namespace, localName)
参数
返回值
被移除的 Attr 节点。
异常
NotFoundErrorDOMException-
如果没有具有给定命名空间和本地名称的属性,则会抛出此异常。
示例
js
const parser = new DOMParser();
const xmlString =
'<warning ob:one="test" xmlns:ob="http://www.example.com/ob">Beware!</warning>';
const doc = parser.parseFromString(xmlString, "application/xml");
const pre = document.querySelector("pre");
const warning = doc.querySelector("warning");
const attrMap = warning.attributes;
let result = `The 'ob:one' attribute initially contains '${attrMap["ob:one"].value}'.\n`;
result += "We remove it.\n\n";
attrMap.removeNamedItemNS("http://www.example.com/ob", "one");
result += attrMap["ob:one"]
? "And 'ob:one' still exists."
: "And 'ob:one' is no more to be found.";
pre.textContent = result;
规范
| 规范 |
|---|
| DOM # dom-namednodemap-removenameditemns |
浏览器兼容性
加载中…