比较两个表行,如果匹配则删除 [英] Compare two tables rows and remove if match

查看:69
本文介绍了比较两个表行,如果匹配则删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在JQuery中帮助我吗? 我的网站 leftTable rightTable 中有两个表,它们具有相同的列名.我从数据库填写了 leftTable ,但是 rightTable 却只包含一些行.我想做的是不要在 leftTable 中显示(或删除) rightTable 中存在的那些行!

Could anyone help me please in JQuery? I have two tables on my site leftTable and rightTable with same column names. The leftTable I fill up from a DB, but the rightTable it just contains some rows. What I would like to do is to not show (or remove) in the leftTable those rows which are exist in the rightTable!

我尝试过:

$("#tableLeft tr").each(function(){
    if($(this).find("td")[0].innerHTML == $("#tableRight tr").find("td")[0].innerHTML)
    {
        $(this).remove;
    }
});

推荐答案

我想你有这样的东西:

<table id="T1">

    <tr><td>111</td></tr>
    <tr><td>222</td></tr>
    <tr><td>333</td></tr>

</table>


<table id="T2">

    <tr><td>444</td></tr>
    <tr><td>111</td></tr>
    <tr><td>333</td></tr>

</table>

要从ID为"T2"的表格中删除行,您可以执行以下操作:

To remove rows from table with id="T2" you can do something like this:

$('#T1 tr').each(function(){

    var currentRowHTML=$(this).html();

    $('#T2 tr').each(function(){
        if($(this).html()===currentRowHTML){
            $(this).remove();
        }
    });
});

这篇关于比较两个表行,如果匹配则删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆