比较两行 (HTML Table) 数据,即 row[i] 与 row[i+1] 并使用 Jquery/Javascript 突出显示更改

Compare two rows (HTML Table) data i.e..row[i] with row[i+1] and highlight changes using Jquery/Javascript

比较两行数据,即 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;
                });
            });