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