美文网首页
js 获取计算后样式

js 获取计算后样式

作者: 发光驴子 | 来源:发表于2017-09-13 23:29 被阅读0次

/js获取计算后的样式,也可以说获取最终样式/

function getStyle(obj,attr){
//那个元素,obj,什么样式attr
//并且注意,只能取某一个样式,复合样式是取不到的,比如background,因为有backgroundColor。等等
if(obj.currentStyle){
    //如果currentStyle为真,那么就是IE下,使用IE专用的currentStyle
    return obj.currentStyle[attr];
}
else{
    //不是IE,那么就使用,getComputedStyle
    //getComputedStyle(元素,"false") 火狐专用,第二个参数可以不给,
    return getComputedStyle(obj,false)[attr];
}
}

相关文章

网友评论

      本文标题:js 获取计算后样式

      本文链接:https://www.haomeiwen.com/subject/klhrsxtx.html