StylePropertyMapReadOnly: forEach() 方法
StylePropertyMapReadOnly.forEach() 方法對 StylePropertyMapReadOnly 的每個元素執行一次提供的函式。
語法
js
forEach(callbackFn)
forEach(callbackFn, thisArg)
引數
callbackFn-
要為每個元素執行的函式,接受三個引數
currentValue-
正在處理的當前元素的值。
index可選-
正在處理的當前元素的索引。
array可選-
呼叫
forEach()的 StylePropertyMapReadOnly。
thisArg可選-
執行
callback時用作this(即引用Object)的值。
返回值
無(undefined)。
示例
這是一個在檢索到的 Element.computedStyleMap() 上使用 forEach() 的示例。
js
// get a button element
const buttonEl = document.querySelector(".example");
// we can retrieve all computed styles with `computedStyleMap`
const allComputedStyles = buttonEl.computedStyleMap();
// forEach will allow us to run code over each prop/val pair
allComputedStyles.forEach((elem, index, arr) => {
// code to run for each pair
});
規範
此特性似乎未在任何規範中定義。瀏覽器相容性
載入中…