CSSStyleRule:styleMap 属性
基线 2026>
最近可用
自 2026年11月 起,此特性已在最新浏览器中得到支持。但在较旧的设备或浏览器中可能无法运行。
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> |