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 |
瀏覽器相容性
載入中…