CSSStyleRule: styleMap property
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thuộc tính chỉ-đọc styleMap của giao diện CSSStyleRule trả về một đối tượng StylePropertyMap cung cấp quyền truy cập vào các cặp thuộc tính-giá trị của quy tắc.
Giá trị
Một đối tượng StylePropertyMap.
Ví dụ
Ví dụ sau cho thấy cách dùng styleMap để sửa đổi một style bằng phương thức StylePropertyMap.set().
js
const stylesheet = document.styleSheets[0];
Object.values(stylesheet.cssRules).forEach((block) => {
if (block.selectorText === "button") {
block.styleMap.set("--main-color", "black");
}
});
Thông số kỹ thuật
| Specification |
|---|
| CSS Typed OM Level 1> # dom-cssstylerule-stylemap> |