-2

首先,我克隆以下 div 列表:

<div class=".a_list"><p><input type="checkbox" />Testing A list</p></div>
<div class=".a_list"><p><input type="checkbox" />Testing A list</p></div>
<div class=".a_list"><p><input type="checkbox" />Testing A list</p></div>
$(".a_list").each(function(){
    $(this).clone().appendTo("#list").wrap("<li />");
});

在将克隆添加到列表之前如何检查#list

4

1 回答 1

0

您应该首先.从类名中删除。你可以使用filtertext方法。

var $list = $('#list');
$(".a_list").each(function(){
    var $that = $(this); // Sorry, note that there was a typo here
    var e = $list.find('li').filter(function(){
         return $(this).text() === $that.text();
    }).length === 0;
    if (e) {
       $that.clone().wrap("<li/>").appendTo($list);
    }
});
于 2013-01-06T21:25:10.057 回答