当我们读取当前元素的当前样式时,IE支持currentStyle 但是其他浏览器支持getcomputedStyle();
<button id="btn2">按钮2</button> <div id="box">
btn2.onclick = function(){ if(window.getComputedStyle){ alert(getComputedStyle(box,null)["backgroundColor"]) }else{ alert(box.currentStyle.backgroundColor) } }if里面必须写window的属性值,否则报错不往下执行