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"));

 

转载于:https://www.cnblogs.com/rubekid/p/4059359.html

你可能感兴趣的:(javascript获取标签样式(获取背景为例))