getComputedStyle获取到的是经过浏览器运算后的样式ie6-8不兼容
currentStyle chorme FF不兼容
function getStyle(obj,attr){
/*if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj)[attr];
}*/
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj)[attr];
}
getStyle:
如果获取到的是复合样式,改成单一的样式:backgroundColor 不要用来做判断 img 先对src 可以赋值
不要用空格 不然会undefined
不要获取未设置后的样式