JS通过兼容性写法获取样式
获取非行内样式可以使用以下方式:
一 IE中使用box.currentStyle.width
二 非IE浏览器中使用getComputedStyle(box,null).width
一 IE中使用box.currentStyle.width
二 非IE浏览器中使用getComputedStyle(box,null).width
// 兼容处理
if (box.currentStyle) {
box.currentStyle.width;
}else{
getComputedStyle(box,false).width;
}
function getStyle(obj,sty){
if (obj.currentStyle) {
return obj.currentStyle[sty];
}else{
return getComputedStyle(obj,false)[sty];
}
}
console.log(getStyle(box,"height"));