window.onload = function(){
var bx1 = document.getElementById("box1");
document.querySelector(".btn1").onclick = function(){
bx1.style.height = "400px";
bx1.style.width = "400px";
bx1.style.backgroundColor = "red";
}
document.querySelector(".btn2").onclick = function(){
if(window.getComputedStyle){
// 正常浏览器
alert(getComputedStyle(bx1,null).backgroundColor);
}else{
//IE8
alert(bx1.currentStyle.backgroundColor);
}
}
}
js基础---正常浏览器与IE获取元素的样式 getComputedStyle/元素.currentStyle
原文:https://www.cnblogs.com/leiyanting/p/15229315.html