通过style方式获取样式有很大的局限性,只能返回内嵌样式。
function getStyle(obj, name) {
// 判断是否存在currentStyle
if (obj.currentStyle) {
// IE下使用currentStyle
return obj.currentStyle[name];
}
else {
// 用getComputedStyle方法
return getComputedStyle(obj, false)[name];
}
}