js获得当前元素的样式

利用currentStyle()和ComputedStyle()

1 通常用法:

balance为类名

window.getComputedStyle(document.querySelector(".balance"), null).backgroundColor;

window.getComputedStyle(document.querySelector(".balance"), null).fontSize;

 

2 封装一个函数:

function getstyle(obj, key) {

    if (obj.currentStyle) {

        return  obj.currentStyle.key;

    } else {

        Return  getComputedStyle(obj, mull).key;

    }

}

封装进getstyle函数

 

posted on 2017-08-11 15:59  ranyonsue  阅读(1169)  评论(0编辑  收藏  举报

导航