javascript获取标签样式(获取背景为例)

function getStyle(el){
    if(window.getComputedStyle){
        return window.getComputedStyle(el,null); 
    }
    return el.currentStyle;
}

function getStyleValue(el, name){
    var style = getStyle(el);
    return style[name];
}

console.log(getStyle(document.body));
console.log(getStyleValue(document.body, "backgroundImage"));

 

posted @ 2014-10-29 14:04  rubekid  阅读(471)  评论(0编辑  收藏  举报