Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从html中如何使用js或jquery删除重复的td标记值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 从html中如何使用js或jquery删除重复的td标记值

Javascript 从html中如何使用js或jquery删除重复的td标记值,javascript,jquery,html,Javascript,Jquery,Html,示例html: <tbody> <tr> <th style="width: 65%;">FD Name</th> <th style="width:35%;">PDF</th> </tr> <tr> <td>NT BT Small Cap FD</td> <td>

示例html:

<tbody>
    <tr>
        <th style="width: 65%;">FD Name</th>
        <th style="width:35%;">PDF</th>
    </tr>
    <tr>
        <td>NT BT Small Cap FD</td>
        <td>
            <div>
                <a target="_self" onclick="window.open('URL/2509-pqr-statement.pdf'); return false;">ST</a> (55 kb)</div>
        </td>
    </tr>   <tr>
        <td>NT GB GT FD</td>
        <td>
            <div>
                <a target="_self" onclick="window.open('URL/12111-pqr-statement.pdf'); return false;">ST</a> (61 kb)</div>
        </td>
    </tr>   <tr>
        <td>NT GB GT FD</td>
        <td>
            <div>
                <a target="_self" onclick="window.open('URL/12111-pqr-statement.pdf'); return false;">ST</a> (61 kb)</div>
        </td>
    </tr>   <tr>
        <td>NT Mutual GB Discovery FD</td>
        <td>
            <div>
                <a target="_self" onclick="window.open('URL/4684-pqr-statement.pdf'); return false;">ST</a> (69 kb)</div>
        </td>
    </tr>   <tr>
        <td>NT Mutual GB Discovery FD</td>
        <td>
            <div>
                <a target="_self" onclick="window.open('URL/4684-pqr-statement.pdf'); return false;">ST</a> (69 kb)</div>
        </td>
    </tr>   
</tbody>

FD名称
PDF
新界BT小型股FD
ST(55 kb)
NT GB GT FD
ST(61 kb)
NT GB GT FD
ST(61 kb)
NT相互GB发现FD
ST(69KB)
NT相互GB发现FD
ST(69KB)
如何删除重复的td值,例如NT GB GT FD、NT相互GB发现FD是重复的。
使用JS/jQuery的任何指针或想法?

当您沿着每一行走下去时,使用一个对象来存储文本以进行查找。如果已经看到文本,则删除行

var textLookup={};

$('#my-table tbody tr:gt(0)').each(function(){
   var $row = $(this),
       targetText = $row.find('td:first').text().trim();
       // may want to make sure the text isn't empty string also??
       if(textLookup[targetText]){
          $row.remove()
       }
       textLookup[targetText]=true; 
});

duplicate
是映射每个
tr
第一个td子对象的对象。如果从未在对象内部看到这些子对象,则
duplicate
将保留它。另一方面,如果这些子级已经在
复制
中,那么我们将删除此
td
.parent()
,这是它的
tr

var duplicate = {};

$('tr td:first-child').each (function () {
    var fdName = $(this).html()

    if (duplicate.hasOwnProperty(fdName)) {
       $(this).parent().remove();
    } else {
       duplicate[fdName] = 'true';
    }
});

工作JSFIDLE:

比较单元格数据,如果两者相等,则删除第二个实例?您是否询问重复的行或重复的单元格?您是否发现以下方法代码有任何问题-->var seen={}$('table tr').each(function(){var txt=$(this.text();if(seen[txt])$(this.remove();else seen[txt]=true;});您是否发现以下方法代码有任何问题--->var seen={}$('table tr').each(function(){var txt=$(this.text();if(seen[txt])$(this.remove();else seen[txt]=true;});