比较2个表的值并突出显示不同的行 [英] Comparing values of 2 tables and highlighting the rows that are different
本文介绍了比较2个表的值并突出显示不同的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要比较两个相同但包含一些不同数据的表中的值.我必须找到并强调该差异.我该怎么办?
I need to compare values from two tables that are identical but contain some different data. I must find and highlight that diff. How can I do that?
<table class="TableA">
<tr>
<td>Head1</td>
<td>Some_Value</td>
</tr>
<tr>
<td>Head2</td>
<td>SomeValue</td>
</tr>
</table>
<table class="TableB">
<tr>
<td>Head1</td>
<td>Some_Value</td>
</tr>
<tr>
<td>Head2</td>
<td>SomeValueDiffValue</td>
</tr>
</table>
我需要比较这两个表并使用jquery突出显示值单元格中的差异,在上面的示例中,我需要在第二个表中突出显示SomeValueButDiff
I need to compare this two tables and highlight diff in value cells with jquery, in above example I need to highlight SomeValueButDiff in second table
好吧,我将Ahmet的代码修改为:
Ok, I modified Ahmet's code into this:
$(".TableB tr").each(function () {
if ($(this).find("td")[1].innerHTML !=
$(".TableA").find("td")[1].innerHTML) {
$(this).find("td")[1].bgColor = "red";
}
});
这对我有用,艾哈迈德.
This works for me, thx Ahmet.
推荐答案
如果连续有多个数据单元格,则需要编辑代码.
You need to edit code if you have multi data cells in a row.
$(".TableA tr").each(function () {
if ($(this).find("td")[0].innerHTML != $(this).find("td")[1].innerHTML) {
$(this).find("td")[0].bgColor = "red";
}
});
这篇关于比较2个表的值并突出显示不同的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文