obj.style.backgroundColor为什么取不到值?

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;
}

没有评论:

发表评论

我的照片
本人毕业后一直从事服装营销工作,后爱上编程。偏爱开源软件,认为开源和分享是今后的主流。原本是用LAMP开发平台,现在采用BAPP平台,BAPP即 FreeBSD,Apache,PostgreSQL,PHP。主要开发B/S架构的呼叫中心,CRM,库存管理,销售管理,网站购物,在线记账等。




©2008 The FreeBAPP Project. All rights reserved.