作者:tttrj | 来源:互联网 | 2023-09-10 14:01
我有一张桌子(长得多又宽很多),我希望能够突出显示重复的值
在每列中。目前,我可以在1列上执行此操作,但不能进行多次。
OnValueChange={(itemValue,itemIndex) =>
this.setState({crash_type: itemValue})
}>
$(function() {
var tableRows = $("#sortable tbody tr"); //find all the rows
var colors = ["red","blue","green","yellow","#f5b"];
var rowValues = {};
tableRows.each(function() {
var rowValue = $(this).find(".content").html();
if (!rowValues[rowValue]) {
var rowComposite = new Object();
rowComposite.count = 1;
rowComposite.row = this;
rowComposite.color = colors.shift();
rowValues[rowValue] = rowComposite;
} else {
var rowComposite = rowValues[rowValue];
rowComposite.count++;
$(this).css('backgroundColor',rowComposite.color);
$(rowComposite.row).css('backgroundColor',rowComposite.color);
}
});
});
您可以使用tr td:nth-child
选择器选择所需的“列”。参见以下示例:
$(function() {
var tableRows = $("tr td:nth-child(1)"); //find all the rows
var colors = ["red","blue","green","yellow","#f5b"];
var rowValues = {};
tableRows.each(function() {
var rowValue = $(this).text();
if (!rowValues[rowValue]) {
var rowComposite = new Object();
rowComposite.count = 1;
rowComposite.row = this;
rowComposite.color = colors.shift();
rowValues[rowValue] = rowComposite;
} else {
var rowComposite = rowValues[rowValue];
rowComposite.count++;
$(this).css('backgroundColor',rowComposite.color);
$(rowComposite.row).css('backgroundColor',rowComposite.color);
}
});
// Second column
var tableRows = $("tr td:nth-child(2)"); //find all the rows
// var colors = ["red",rowComposite.color);
}
});
});