DOM
Element 接口的 removeAttributeNS() 方法从元素中移除指定命名空间的指定属性。
如果你正在处理 HTML,并且你不需要指定要移除的属性属于某个特定的命名空间,那么使用 Element.removeAttribute() 方法即可。
语法
removeAttributeNS(namespace, attrName)
参数
namespace:一个表示包含该属性的命名空间的字符串。attrName:一个表示要从当前节点移除的属性的名称的字符串。
返回值
无(undefined)。
示例
// 给定:
// <div id="div1" xmlns:special="http://www.mozilla.org/ns/specialspace"
// special:specialAlign="utterleft" width="200px" />
d = document.getElementById("div1");
d.removeAttributeNS("http://www.mozilla.org/ns/specialspace", "specialAlign");
// 现在:<div id="div1" width="200px" />
规范
浏览器兼容性
参见
- Element.hasAttributeNS()
- Element.getAttributeNS()
- Element.setAttributeNS()
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
