currentStyle和getComputedStyle的区别

currentStyle和getComputedStyle返回的都是字符串,比如返回的是“10px”。

currentStyle和getComputedStyle都为只读不可写,currentStyle仅支持IE,getComputedStyle支持除IE以外的浏览器,所以两者要一起使用。

function css(obj, attr) {
        if (obj.currentStyle) {
            return obj.currentStyle[attr];
        } else {
            return getComputedStyle(obj, false)[attr];
        }
    }

四种style总结:

 

posted @ 2017-05-19 10:10  小Y爱学前端  阅读(155)  评论(0编辑  收藏  举报