首页 > 其他 > 详细

getComputedStyle与currentStyle获取样式(style/class)

时间:2015-09-08 15:21:18      阅读:243      评论:0      收藏:0      [点我收藏+]

获取通过class 获取样式,obj.currentStyle.样式名          -> IE系列浏览器,getComputedStyle(obj, false)[name] -> chrome FF IE9+

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com">
<meta name="copyright" content="智能社 - zhinengshe.com">
<title>智能社 - www.zhinengshe.com</title>
<style>
#div1 { width:300px; height:200px; background:#ccc; }
</style>
<script>
 //obj.currentStyle.样式名          -> IE系列浏览器
 //getComputedStyle(obj, false)[name] -> chrome FF IE9+

window.onload=function (){
    var oDiv=document.getElementById(div1);
    console.log(getStyle(oDiv, width))
    function getStyle(obj,name){
            return obj.currentStyle ?  obj.currentStyle[name] : getComputedStyle(obj,false)[name];
    }
};
</script>
</head>

<body>
    <div id="div1"></div>
</body>
</html>

参考  http://www.jb51.net/article/34863.htm

getComputedStyle与currentStyle获取样式(style/class)

原文:http://www.cnblogs.com/heboliufengjie/p/4791512.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!