获取指定元素的当前的样式

/*

* 参数
* obj 要获取样式的元素
* name 要获取的样式名
*/

function getStyle(obj, name) {

    if(window.getComputedStyle) {
        //正常浏览器的方式,具有getComputedStyle()方法
        return getComputedStyle(obj, null)[name];
    } else {
        //IE8的方式,没有getComputedStyle()方法
        return obj.currentStyle[name];
    }

}
posted @ 2020-01-16 15:22  路飞910  阅读(196)  评论(0编辑  收藏  举报