此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

CSSStyleRule:styleMap 属性

有限可用

此特性不属于基线,因为它尚未在主流浏览器中得到支持。

Want more browser support for this feature? Tell us why.

CSSStyleRule 接口的只读属性 styleMap 返回提供对规则的属性—值对的访问的 StylePropertyMap 对象。

StylePropertyMap 对象。

示例

以下示例展示了如何使用 styleMap 并通过 StylePropertyMap.set() 方法修改样式。

js
const stylesheet = document.styleSheets[0];

Object.values(stylesheet.cssRules).forEach((block) => {
  if (block.selectorText === "button") {
    block.styleMap.set("--mainColor", "black");
  }
});

规范

规范
CSS Typed OM Level 1
# dom-cssstylerule-stylemap

浏览器兼容性