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① |
瀏覽器相容性
載入中…