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 |
瀏覽器相容性
載入中…