CSSStyleRule:styleMap 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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");
}
});
规范
| Specification |
|---|
| CSS Typed OM Level 1> # dom-cssstylerule-stylemap> |
浏览器兼容性
Loading…