比较两行数据,即 row[i]
与 row[i+1]
并使用 Jquery/Javascript
突出显示更改。它用于显示文物的历史。查了很多答案,却一片空白。任何有关 jsfiddle
示例的帮助将不胜感激。
想要一些东西来转换这个 fiddle 的作用.. http://jsfiddle.net/hA5G8/18/ .它比较同一行内的列。只需比较行之间的列即可。
最佳答案
这是更新后的 fiddle http://jsfiddle.net/Lbuxpmyq/1/
谢谢!!
HTML
<table id="coa_history_data">
<tr class="data-in-table">
<th>old Name</th>
<th>New Name</th>
<th>Old Phone</th>
<th>New Phone</th>
<th>Old Age</th>
<th>New Age</th>
</tr>
<tbody>
<tr class="data-in-table">
<td>Alphy</td>
<td>Alphy</td>
<td>015</td>//should be highlited
<td>016</td>//should be highlited
<td>23</td>//should be highlited
<td>24</td>//should be highlited</tr>
<tr class="data-in-table">
<td>Tom</td>
<td>Tom</td>
<td>12</td>
<td>12</td>
<td>65</td>//should be highlited
<td>30</td>//should be highlited</tr>
<tr class="data-in-table">
<td>will</td>
<td>will</td>
<td>12</td>
<td>12</td>
<td>20</td>
<td>20</td>
</tr>
</tbody>
</table>
JQuery
$("#coa_history_data tbody tr.data-in-table").each(function () {
var i=0;
$(this).find('td').each(function (index) {
var currentCell = $(this);
var nextCell = $(this).closest('tr').next('tr').find('td').eq(i).length > 0 ? $(this).closest('tr').next('tr').find('td').eq(i) : null;
if ( currentCell.text() !== nextCell.text()) {
currentCell.css('backgroundColor', 'yellow');
}
i=i+1;
});
});
关于javascript - 比较两行(HTML 表)数据,即 row[i] 与 row[i+1] 并使用 Jquery/Javascript 突出显示更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31580419/