Element.setAttributeNS()
setAttributeNS
添加一个新属性或更改具有给定命名空间和名称的一个属性的值。
句法
element.setAttributeNS(namespace,name,value)
namespace
是指定属性的命名空间的一个字符串。name
是标识要设置的属性的一个字符串。value
是新属性的所需字符串值。
范例
let d = document.getElementById("d1"); d.setAttributeNS("http://www.mozilla.org/ns/specialspace", "align", "center");
注释
DOM methods dealing with element's attributes:
Not namespace-aware, most commonly used methods | Namespace-aware variants (DOM Level 2) | DOM Level 1 methods for dealing with Attr nodes directly (seldom used) |
DOM Level 2 namespace-aware methods for dealing with Attr nodes directly (seldom used) |
---|---|---|---|
setAttribute (DOM 1) |
setAttributeNS |
setAttributeNode |
setAttributeNodeNS |
getAttribute (DOM 1) |
getAttributeNS (en-US) |
getAttributeNode |
getAttributeNodeNS |
hasAttribute (DOM 2) |
hasAttributeNS |
- | - |
removeAttribute (DOM 1) |
removeAttributeNS |
removeAttributeNode |
- |