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

标签 javascript jquery html datatables html-table

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

相关文章:

javascript - 检测破折号中的页面变化

javascript - 在一个div中居中多个div

javascript - 如何正确使用 toggleClass 更改 div css?

jquery - 奇怪的 z-index 在 safari 中带有 rotateY 但在 chrome 和 firefox 中没有

javascript - 尝试在前置元素:上添加点击事件

javascript - 为什么对象引用可以在内部函数成员中访问,但不能在内部属性成员中访问?

javascript - 将 JavaScript 添加到 MVC 4 .NET Bootstrap Web 应用程序

javascript - 你如何根据浏览器宽度用 javascript 更改 img src?

html - 固定页眉中的响应式透明 Logo

javascript - 可点击的 div 标签使用 not() 该 div 内的任何 div 标签