用jQuery怎么得到对象的背景色

gkmzk 2011-03-19 10:16:10
用jQuery怎么得到<tr>对象的背景色,小弟急用,拜求!
...全文
958 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
gkmzk 2011-03-19
  • 打赏
  • 举报
回复
那在FF下判断$("#kk tr:first").css("backgroundColor") == "rgb(255,0,0)"吗?还是返回的False
zell419 2011-03-19
  • 打赏
  • 举报
回复
用window.navigator.userAgent.indexOf("Firefox")>=1
分别处理 。
gkmzk 2011-03-19
  • 打赏
  • 举报
回复
对,我用的是FF,那在FF应该怎么判断呢?
夷陵小妞 2011-03-19
  • 打赏
  • 举报
回复
if($("#kk tr:first").css("backgroundColor") == "#ff0000"){
alert("true");
}
zell419 2011-03-19
  • 打赏
  • 举报
回复
我试了是fire fox 才返回rgb什么的 。
区分下浏览器行吗 ?
gkmzk 2011-03-19
  • 打赏
  • 举报
回复
改成大写"#FF0000"还是不对,返回还是False
夷陵小妞 2011-03-19
  • 打赏
  • 举报
回复
if($("#kk tr:first").css("background-color") 取到的颜色编码是大写“#FF0000”
你应该跟“#FF0000”比较·判断是否相等

gkmzk 2011-03-19
  • 打赏
  • 举报
回复
而判断if($("#kk tr:first").css("background-color")=="rgb(255,0,0)")怎么返回false啊,
无栈程序猿 2011-03-19
  • 打赏
  • 举报
回复
$("#kk tr:first").css("background-color")
gkmzk 2011-03-19
  • 打赏
  • 举报
回复
不过,运行之后怎么得到 rgb(255,0,0)
gkmzk 2011-03-19
  • 打赏
  • 举报
回复
是$("#kk tr:first").css("backgroundColor")还是$("#kk tr:first").css("background-color")
hongmei85 2011-03-19
  • 打赏
  • 举报
回复
这样也可以
		<script type="text/javascript" src="js/jq.js"></script>
</head>
<script type="text/javascript">
<!--
$(document).ready(function(){alert($("#kk tr:first").css("backgroundColor"));}
)
//-->
</script>
<body>
<table border="1" id="kk">
<tr style="background-color:#ff0000">
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
hongmei85 2011-03-19
  • 打赏
  • 举报
回复
<script type="text/javascript" src="js/jq.js"></script>
</head>
<script type="text/javascript">
<!--
$(document).ready(function(){alert($("#kk tr:first").attr("bgcolor"));}
)
//-->
</script>
<body>
<table border="1" id="kk">
<tr bgcolor="#ff0000">
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
lazyboy_wu 2011-03-19
  • 打赏
  • 举报
回复


//Helper function to convert a digit to a two column Hex representation
function toHex(N) {
if (N==null) return "00";
N=parseInt(N); if (N==0 || isNaN(N)) return "00";
N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
}

//Function to convert rgb() format values into normal hex values
function RGBtoHEX(str)
{
if (str.substring(0, 3) == 'rgb') {
var arr = str.split(",");
var r = arr[0].replace('rgb(','').trim(), g = arr[1].trim(), b = arr[2].replace(')','').trim();
var hex = [
toHex(r),
toHex(g),
toHex(b)
];
return "#" + hex.join('');
}
else{
return str;
}
}

// 大写#FF0000
alert(RGBtoHEX($("#kk tr:first").css("backgroundColor")) == "#FF0000")
gkmzk 2011-03-19
  • 打赏
  • 举报
回复
http://www.phpied.com/rgb-color-parser-in-javascript/
这个页面打不开,哈哈
showenxxx 2011-03-19
  • 打赏
  • 举报
回复
顺便看看这个http://www.phpied.com/rgb-color-parser-in-javascript/
把颜色的表达转到同一的样式
showenxxx 2011-03-19
  • 打赏
  • 举报
回复
楼主看看在IE,FF下值是多少
http://jsfiddle.net/wPBvg/

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧