码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-10-29 14:37:22      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   java   sp   div   on   

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

 

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

标签:style   blog   io   color   ar   java   sp   div   on   

原文地址:http://www.cnblogs.com/rubekid/p/4059359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!