StylePropertyMapReadOnly: getAll() 方法
getAll() 方法是 StylePropertyMapReadOnly 接口的一部分,它返回一个包含给定属性值的 CSSStyleValue 对象数组。
语法
js
getAll(property)
参数
property(属性)-
要检索所有值的属性名称。
返回值
一个 CSSStyleValue 对象数组。
示例
以下示例将 getAll() 与 background-image 属性一起使用。它返回一个 Array,其中包含每个已声明的背景图像的项目。
js
// get a button element
const buttonEl = document.querySelector("button");
// we can retrieve all computed styles with `computedStyleMap`
const allComputedStyles = buttonEl.computedStyleMap();
// use getAll() with the background image property
const allBkImages = allComputedStyles.getAll("background-image");
console.log(allBkImages); // logs an array with each background image as an item
规范
| 规范 |
|---|
| CSS 类型化 OM Level 1 # dom-stylepropertymapreadonly-getall |
浏览器兼容性
加载中…