我一直试图让我自己的工作,现在已经放弃。我得到了SO和其他Google网站上的大部分代码。jquery更改表格单元格颜色
我所试图做的是改变的我的第一<td>
基于价值的background-color
我最后<td>
这是我的时刻,但我似乎无法得到任何其他颜色的工作等比第一if statement
:(
$(document).ready(function()
{
$("#tableData tr:not(:first)").each(function() {
//get the value of the table cell
var Colour = $(this).find("td:nth-child(4)").html();
alert(Colour);
//check the colour
if (Colour = "red")
{
//change the color of the background
$(this).find("td:nth-child(1)").css("background-color", "red");
}
else if (Colour = "green")
{
$(this).find("th:nth-child(1)").css("background-color", "green");
}
else if (Colour = "blue")
{
$(this).find("th:nth-child(1)").css("background-color", "blue");
}
});
});
我也为您创建了FIDDLE,看看有什么我遇到。能不能请您让我知道我怎么会有这种变化动态地根据单元格的值?
谢谢! 迈克
变化'='一样简单到== == – 2014-11-04 10:10:06
@JohnStephen这似乎没有任何区别。 – Mike 2014-11-04 10:11:40