[英]Change background-color for td
如果background color
TD的== color1
然后改变td background-color
,以COLOR2。
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-condensed">
<tbody><tr><td style="background-color:#00FF60">1</td></tr></tbody></table>
我的jquery:
$(document).ready(function(){
if($('td').css('background-color') == 'rgb(0, 255, 96)') {
$('td').css('background-color','red');
}
})
首先,你必须包含jQuery。 然后循环每个td
元素并根据首选项设置background-color
尝试:
$("td").each(function (index) {
if ($(this).css('background-color') == 'rgb(0, 255, 96)') {
$(this).css('background-color', 'red');
}
});
您还没有将jQuery库添加到jsfiddle(从左侧的下拉列表添加它)。 你还需要使用.each()
迭代td
,然后检查td
background-color
,参见下面的代码
$(document).ready(function(){
$('td').each(function(){
if($(this).css('background-color') == 'rgb(0, 255, 96)') {
$(this).css('background-color','red');
}
});
});
Frist,包括jquery库; 第二步,删除“$(document).ready(function(){”,因为您选择了“onLoad”。将以下代码替换为您的JavaScript部分
$('td').each(function(){
if($(this).css('background-color') === 'rgb(0, 255, 96)') {
$(this).css('background-color','red');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.