码迷,mamicode.com
首页 > Web开发 > 详细

arguments | json | currentStyle

时间:2015-06-02 00:10:05      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

arguments |  json | currentStylefor( var i in json);

获取非行间样式,在IE下用 currentStyle(IE-9) ,在chrome 和 firfox 下用 getComputedStyle. 其中判断IE还是chrome、firfox是根据 obj.currentStyle ,ie为ture,FF为false。

获取非行间样式
        window.onload=function(){
            var oDiv2 = document.getElementById(‘div2‘);
            IE:
            alert(oDiv2.currentStyle.width);

            chrome、firfox:
            alert(getComputedStyle(oDiv2,null).width);/*其中null的位置是垃圾位置,随便写什么都可以*/ 

            改写:
            if(oDiv2.currentStyle){
                alert(oDiv2.currentStyle.width);
            }
            else{
                alert(getComputedStyle(oDiv2,null).width);
            }
        }
      }

  封装:
        function getStyle(obj,name){
    if(obj.currentStyle){
        return obj.currentStyle[name];
    }else{
        return getComputedStyle(obj,null)[name];
    }

arguments | json | currentStyle

标签:

原文地址:http://www.cnblogs.com/yinpan/p/4545058.html

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