1.IE浏览器下最终样式的获取
var divEle = document.getElementById("divId");
var backgroundColor = divEle.currentStyle.backgroundColor;
样式只读,不能改
2.DOM浏览器下最终样式的获取
var divEle = document.getElementById("divId");
var backgroundColor = document.defaultView.getComputedStyle(divEle, null).backgroundColor;
3.最终样式兼容性处理
function getFinalStyle(node, propertyVal) {
if (!node.currentStyle) {//dom规范浏览器
return getComputedStyle(node, null)[propertyVal];
} else {//ie8及其以下
return node.currentStyle[propertyVal];
}
}
var fontSizeVal = getFinalStyle(document.body, "fontSize");
console.info(fontSizeVal);