jquery remove duplicate li

后端 未结 5 1783
青春惊慌失措
青春惊慌失措 2020-12-05 16:06
  • microsoft
  • microsoft
  • apple
  • apple
5条回答
  •  悲&欢浪女
    2020-12-05 16:42

    I have used @Thariama solution in the past, but I have compatibility problems with IE6 (I still needs to support this dinosaur).

    If the item repeats, so remove it from ul. It works with dynamic added li.

                var seen = {};
                $("ul#emails_exclusion_list").find("li").each(function(index, html_obj) {
                    txt = $(this).text().toLowerCase();
    
                    if(seen[txt]) {
                        $(this).remove();
                    } else {
                        seen[txt] = true;
                    }
                });
    

提交回复
热议问题