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()