得到元素真实的背景颜色的函数
作者:Longbill 时间:2008-05-20 12:04:00
传入参数一个,为元素的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;
}
标签:函数,背景色,js
0
投稿
猜你喜欢
Python计算回文数的方法
2022-04-02 05:08:07
Python中Django框架利用url来控制登录的方法
2022-03-27 18:15:37
SQL Server 数据库索引其索引的小技巧
2012-07-11 15:55:02
python matplotlib画图库学习绘制常用的图
2023-11-27 20:32:03
go使用makefile脚本编译应用的方法小结
2024-04-25 15:17:57
基于python二叉树的构造和打印例子
2023-05-16 15:35:45
使用Python的Twisted框架编写非阻塞程序的代码示例
2021-01-22 16:20:51
10分钟彻底搞懂Http的强制缓存和协商缓存(小结)
2024-04-17 10:09:08
Javascript this 关键字 详解
2024-06-07 15:51:18
获取MSSQL 表结构中字段的备注、主键等信息的sql
2024-01-24 14:25:14
在Python中字符串、列表、元组、字典之间的相互转换
2021-08-30 07:09:42
Java常用正则表达式验证类完整实例【邮箱、URL、IP、电话、身份证等】
2022-09-14 05:59:39
tensorflow实现训练变量checkpoint的保存与读取
2023-12-15 18:10:33
asp如何让页面过时并指定一个过时时间?
2010-05-13 16:40:00
详解vue的diff算法原理
2023-07-02 16:49:44
最新Adobe 2022全新上线 Adobe 2022永久免费使用教程
2022-02-01 14:59:07
在 Python 中利用Pool 进行多处理
2022-03-07 13:10:36
通过python检测字符串的字母
2023-01-11 22:49:47
python爬虫库scrapy简单使用实例详解
2022-03-22 23:46:11
利用Matplotlib实现单画布绘制多个子图
2021-10-30 19:33:58