Element:hasAttributeNS() 方法
hasAttributeNS() 方法是 Element 接口的一部分,它返回一个布尔值,指示当前元素是否具有指定命名空间中具有指定名称的属性。
如果您正在处理 HTML 文档,并且不需要将请求的属性指定为特定命名空间的一部分,请改用 hasAttribute() 方法。
语法
js
hasAttributeNS(namespace,localName)
参数
返回值
布尔值。
示例
js
// Check that the attribute exists before you set a value
const d = document.getElementById("div1");
if (
d.hasAttributeNS("http://www.mozilla.org/ns/specialspace/", "special-align")
) {
d.setAttribute("align", "center");
}
规范
| 规范 |
|---|
| DOM # ref-for-dom-element-hasattributens① |
浏览器兼容性
加载中…