Element:removeAttributeNS() 方法

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Element 接口的 removeAttributeNS() 方法从元素中移除指定命名空间的指定属性。

如果你正在处理 HTML,并且你不需要指定要移除的属性属于某个特定的命名空间,那么使用 removeAttribute() 方法即可。

语法

js
removeAttributeNS(namespace, attrName)

参数

  • namespace:一个表示包含该属性的命名空间的字符串。
  • attrName:一个表示要从当前节点移除的属性的名称的字符串。

返回值

无(undefined)。

示例

js
// 给定:
//   <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" />

规范

Specification
DOM
# ref-for-dom-element-removeattributens①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
removeAttributeNS

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见