Jquery 按每列突出显示不同颜色的重复行观察值

Jquery 按每列突出显示不同颜色的重复行观察值,jquery,Jquery,我有一个表(它长得多,宽得多),我希望能够突出显示重复的值 在每列中。目前,我可以在一列上完成这项工作,但不能多次 $(函数(){ var tableRows=$(“#sortable tbody tr”);//查找所有行 变量颜色=[“红色”、“蓝色”、“绿色”、“黄色”、“#f5b”]; var rowValues={}; tableRows.each(函数(){ var rowValue=$(this.find(“.content”).html(); 如果(!rowValues[rowV

我有一个表(它长得多,宽得多),我希望能够突出显示重复的值 在每列中。目前,我可以在一列上完成这项工作,但不能多次

$(函数(){
var tableRows=$(“#sortable tbody tr”);//查找所有行
变量颜色=[“红色”、“蓝色”、“绿色”、“黄色”、“#f5b”];
var rowValues={};
tableRows.each(函数(){
var rowValue=$(this.find(“.content”).html();
如果(!rowValues[rowValue]){
var rowComposite=新对象();
rowComposite.count=1;
rowComposite.row=这个;
rowComposite.color=colors.shift();
rowValues[rowValue]=rowComposite;
}否则{
var rowComposite=rowValues[rowValue];
rowComposite.count++;
$(this.css('backgroundColor',rowComposite.color);
$(rowComposite.row).css('backgroundColor',rowComposite.color);
}
});
});

A.
F
B
F
A.
B
C
D
C
F

您可以使用
tr td:nth child
选择器选择所需的“列”。请参见此示例:

$(函数(){
var tableRows=$(“tr td:nth child(1)”;//查找所有行
变量颜色=[“红色”、“蓝色”、“绿色”、“黄色”、“#f5b”];
var rowValues={};
tableRows.each(函数(){
var rowValue=$(this.text();
如果(!rowValues[rowValue]){
var rowComposite=新对象();
rowComposite.count=1;
rowComposite.row=这个;
rowComposite.color=colors.shift();
rowValues[rowValue]=rowComposite;
}否则{
var rowComposite=rowValues[rowValue];
rowComposite.count++;
$(this.css('backgroundColor',rowComposite.color);
$(rowComposite.row).css('backgroundColor',rowComposite.color);
}
});
//第二列
var tableRows=$(“tr td:nth child(2)”;//查找所有行
//变量颜色=[“红色”、“蓝色”、“绿色”、“黄色”、“#f5b”];
var rowValues={};
tableRows.each(函数(){
var rowValue=$(this.text();
如果(!rowValues[rowValue]){
var rowComposite=新对象();
rowComposite.count=1;
rowComposite.row=这个;
rowComposite.color=colors.shift();
rowValues[rowValue]=rowComposite;
}否则{
var rowComposite=rowValues[rowValue];
rowComposite.count++;
$(this.css('backgroundColor',rowComposite.color);
$(rowComposite.row).css('backgroundColor',rowComposite.color);
}
});
});

A.
F
B
F
A.
B
C
D
C
F

不清楚您的预期结果是什么。当您高亮显示整个A&C行时(可能是因为它们在第1列中匹配),您希望如何处理第2列中的重复项?请分别处理它们