jquery remove duplicate li

后端 未结 5 1781
青春惊慌失措
青春惊慌失措 2020-12-05 16:06
  • microsoft
  • microsoft
  • apple
  • apple
5条回答
  •  春和景丽
    2020-12-05 16:44

    example I find that the script is faster

    var liText = '', liList = $('#myid li'), listForRemove = [];
    
    $(liList).each(function () {
    
      var text = $(this).text();
    
      if (liText.indexOf('|'+ text + '|') == -1)
        liText += '|'+ text + '|';
      else
        listForRemove.push($(this));
    
    })​;
    
    $(listForRemove).each(function () { $(this).remove(); });
    

提交回复
热议问题