arguments | json | currentStyle

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];
    }

posted @ 2015-06-01 21:56  留在世间光年  阅读(148)  评论(0)    收藏  举报