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

浏览器兼容性