Jquery 更改td的背景色
如果tdJquery 更改td的背景色,jquery,colors,background,html-table,Jquery,Colors,Background,Html Table,如果td==color1的背景色,则将td背景色更改为color2 首先,您必须包括jQuery。然后为每个td元素循环,并根据首选项设置背景色 尝试: 您还没有将jQuery库添加到JSFIDLE(从左侧的下拉列表中添加)。 您还需要使用.each()迭代tds,然后检查td的background color,请参见下面的代码 $(document).ready(function(){ $('td').each(function(){ if($(this).css('
==color1
的背景色
,则将td背景色
更改为color2
首先,您必须包括jQuery。然后为每个
td
元素循环,并根据首选项设置背景色
尝试:
您还没有将jQuery库添加到JSFIDLE(从左侧的下拉列表中添加)。 您还需要使用
.each()
迭代td
s,然后检查td
的background color
,请参见下面的代码
$(document).ready(function(){
$('td').each(function(){
if($(this).css('background-color') == 'rgb(0, 255, 96)') {
$(this).css('background-color','red');
}
});
});
首先,包括jquery库;第二,删除“$(document).ready(function(){”,因为您选择了“onLoad”。将以下代码替换为JavaScript部分
$('td').each(function(){
if($(this).css('background-color') === 'rgb(0, 255, 96)') {
$(this).css('background-color','red');
}
});
您尚未添加jquery库。
$("td").each(function (index) {
if ($(this).css('background-color') == 'rgb(0, 255, 96)') {
$(this).css('background-color', 'red');
}
});
$(document).ready(function(){
$('td').each(function(){
if($(this).css('background-color') == 'rgb(0, 255, 96)') {
$(this).css('background-color','red');
}
});
});
$('td').each(function(){
if($(this).css('background-color') === 'rgb(0, 255, 96)') {
$(this).css('background-color','red');
}
});