Remove duplicate 's through jquery

前端 未结 3 572
庸人自扰
庸人自扰 2020-12-01 20:10

I have table which is bound dynamically:


      &l         
3条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 20:41

    Try -

    var seen = {};
    $('table tr').each(function() {
      var txt = $(this).text();
      if (seen[txt])
        $(this).remove();
      else
        seen[txt] = true;
    });
    
    
test1
test1
test2
test1
test2

Code is taken (and very slightly changed) from this question - JQuery: Remove duplicate elements?

提交回复
热议问题