StylePropertyMapReadOnly: has() 方法
has() 方法是 StylePropertyMapReadOnly 介面的一部分,它用於指示指定的屬性是否存在於 StylePropertyMapReadOnly 物件中。
語法
js
has(property)
引數
property(屬性)-
屬性的名稱。
返回值
一個布林值。
示例
這裡我們使用 has() 方法來檢視 padding-top 屬性是否存在於按鈕元素的 style 屬性中。
js
// get the button element
const buttonEl = document.querySelector(".example");
// find what's in the style attribute with attributeStyleMap and has()
const hasPadTop = buttonEl.attributeStyleMap.has("padding-top");
console.log(hasPadTop); // logs true if padding-top is present in style attribute
規範
| 規範 |
|---|
| CSS 型別化 OM Level 1 # dom-stylepropertymapreadonly-has |
瀏覽器相容性
載入中…