我想获得应用于元素的所有样式,例如在 chrome 开发人员工具中,您在右上角看到的名为“计算样式”的部分我想获得所有列表是否有其他简单的方法来获取所有列表和属性(property)
我试过这个 javascript 但它不是我想要的,我必须手动编写 css 属性
我只想早点或默认将所有样式应用于元素
最佳答案
尝试使用这个函数(updated your jsFiddle);
function getComputedStyle(elm, style) {
var computedStyle;
if (typeof elm.currentStyle != "undefined") {
computedStyle = elm.currentStyle;
}
else {
computedStyle = document.defaultView.getComputedStyle(elm, null);
}
return computedStyle[style];
}
getComputedStyle()
函数来自 I does Javascript!
关于javascript - 获取元素的所有计算样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49758649/