window的方法

来源:互联网 发布:小公司网络需求调查表 编辑:程序博客网 时间:2024/06/03 04:55

当我们读取当前元素的当前样式时,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的属性值,否则报错不往下执行