对不起愚蠢的101问题。我不确定为什么这不起作用。我正在尝试遍历使用 getComputedStyle() 返回的各种边距属性
任何帮助将不胜感激提前感谢 - CES
const constContentContainerStyles = window.getComputedStyle(constHTMLContentContainer);
let tmpStylesArray = ["marginTop", "marginLeft", "marginBottom", "marginRight"];
let x = 0;
for (let i = 0; i < tmpStylesArray.length; i++) {
//This throws undefined error
// x = constContentContainerStyles.tmpStylesArray[i];
//This returns 0
x = constContentContainerStyles.getPropertyValue(tmpStylesArray[i]);
console.log(tmpStylesArray[i] + " - " + x);
// returns the correct value
console.log(constContentContainerStyles.marginTop);
};