HTML:标记语言
CSS:样式语言
JavaScript:脚本语言
Web API:编程接口
所有 Web 技术
学习 Web 开发
发现我们的工具
更好地了解 MDN
此特性已相当成熟,可在许多设备和浏览器版本上使用。自 2015 年 7 月以来,各浏览器均已提供此特性。
Element.hasAttribute() 方法返回一个布尔值,表示指定的元素是否具有指定的属性。
Element.hasAttribute()
hasAttribute(name)
name
是一个代表属性名称的字符串。
布尔值。
const foo = document.getElementById("foo"); if (foo.hasAttribute("bar")) { // do something }
加载中…
Element.hasAttributes()
Element.getAttribute()
Element.setAttribute()
Element.removeAttribute()
Element.toggleAttribute()