此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Node.hasAttributes

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

hasAttributes属性返回一个布尔值truefalse,来表明当前元素节点是否有至少一个的属性 (attribute).

语法

js
hasAttributes()

示例

js
var t1 = document.getElementById("table-data");

if (t1.hasAttributes()) {
  // 可以用 t1.attributes 来读取该元素的所有属性
}

规范