style、currentStyle、getComputedStyle的区别和用法

   var oDiv=document.getElementById("test");
   alert("style~~~~"+oDiv.style.color);             //写在样式表里无法读取,只能得到写在行内的
  //属性“getComputedStyle”的值为 null、未定义或不是 Function 对象  说明该浏览器不支持getComputedStyle
  //getComputedStyle     //适用于标准浏览器       IE6、7、8不识别
  //currentStyle             //使用于IE浏览器           标准浏览器不识别

    
    if(oDiv.currentStyle){
        console.log(oDiv.currentStyle.width);
    }else{
        
        console.log(getComputedStyle(oDiv).height);
    }

posted on 2015-05-07 15:09  转角遇到谁  阅读(195)  评论(0编辑  收藏  举报