Element: hasAttributes() 方法

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

Element 介面的 hasAttributes() 方法返回一個布林值,指示當前元素是否具有任何屬性。

語法

js
hasAttributes()

引數

無。

返回值

布林值。

示例

js
let foo = document.getElementById("foo");
if (foo.hasAttributes()) {
  // Do something with 'foo.attributes'
}

規範

規範
DOM
# ref-for-dom-element-hasattributes①

瀏覽器相容性

另見