getComputedStyle和currentStyle

 

 1 /*alert(div.style.width)*/ //null
 2 
 3 function getstyle(obj,name){
 4     if(obj.currentStyle) {
 5     return obj.currentStyle[name];
 6 } else {
 7     return getComputedStyle(obj,null)[name];
 8     }
 9 }
10 alert(getstyle(div,'width'))    
11 }

兼容ie 和非ie浏览器的获取样式写法 ;

zIndex  , marginLeft  backgroundColor 

posted @ 2015-05-26 23:37  小菜鸡12315  阅读(129)  评论(0编辑  收藏  举报