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 |
浏览器兼容性
加载中…