Element:removeAttributeNode() 方法
Element 接口的 removeAttributeNode() 方法会从元素中移除指定的 Attr 节点。
如果您不需要在移除属性节点之前对其进行检查,则可以使用 Element.removeAttribute() 方法代替。
语法
js
removeAttributeNode(attributeNode)
参数
attributeNode-
要从元素中移除的属性节点。
返回值
被移除的属性节点。
异常
NotFoundErrorDOMException-
当元素的属性列表中不包含该属性节点时抛出。
示例
js
// Given: <div id="top" align="center" />
const d = document.getElementById("top");
const d_align = d.getAttributeNode("align");
d.removeAttributeNode(d_align);
// align is now removed: <div id="top" />
注意
如果被移除的属性具有默认值,则会被立即替换。替换的属性将具有相同的命名空间 URI 和本地名称,以及适用的原始前缀。
没有 removeAttributeNodeNS 方法;removeAttributeNode 方法可以移除带命名空间的属性和不带命名空间的属性。
规范
| 规范 |
|---|
| DOM # dom-element-removeattributenode |
浏览器兼容性
加载中…