obj.style.backgroundColor只能赋值,不能取值,取值要用getComputedStyle或者currentStyle。看下例函数:

function getRealStyle(id, styleName){
var element = document.getElementById(id);
var realStyle = null;
if(element.currentStyle){
realStyle = element.currentStyle[styleName];
}else if(window.getComputedStyle){
realStyle = window.getComputedStyle(element, null)[styleName];
}
return realStyle;
}

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *