Ghost全自动系统备份光盘正式版 V4.5 | 硬盘版 V2.0 | 排行榜 TOP50 | 图文推荐 | 玩小游戏
首页 >> JavaScript >> Js实例技巧 >> 得到元素真实的背景颜色的函数

得到元素真实的背景颜色的函数

作者:Longbill 时间:2008-5-20 网友评论条 【

传入参数一个,为元素的id值或元素本身,返回为元素的真实背景色值(字符串)。 值得一提的是IE里面返回的是16进制的值,而Mozilla则是rgb值。

演示地址:  http://longbill.cn/down/sample/getbg.htm

function getBg(element) 
{//author: Longbill (www.longbill.cn) 
if (typeof element == "string") element = document.getElementById(element); 
if (!element) return; 
cssProperty = "backgroundColor"; 
mozillaEquivalentCSS = "background-color"; 
if (element.currentStyle) 
var actualColor = element.currentStyle[cssProperty]; 
else 

var cs = document.defaultView.getComputedStyle(element, null); 
var actualColor = cs.getPropertyValue(mozillaEquivalentCSS); 

if (actualColor == "transparent" && element.parentNode) 
return arguments.callee(element.parentNode); 
if (actualColor == null) 
return "#ffffff"; 
else 
return actualColor; 
}

站长工具
百度相关搜索查询:
相关文章
loading 请稍等,评论加载中...

Aspxhome.com. 中国Asp之家. 版权所有

闽ICP备06017341号