jquery remove duplicate li

后端 未结 5 1786
青春惊慌失措
青春惊慌失措 2020-12-05 16:06
  • microsoft
  • microsoft
  • apple
  • apple
5条回答
  •  猫巷女王i
    2020-12-05 16:29

    Here's a function that will do it, a slightly different way:

    function removeDuplicateItems(id) {
        var ul = $('#' + id);
    
        $('li', ul).each(function() {
            if($('li:contains("' + $(this).text() + '")', ul).length > 1)
                $(this).remove();
        });
    }
    

    Call with removeDuplicateItems('myid');

提交回复
热议问题