-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

.最初にクラス名から削除する必要があります。filterおよびtextメソッドを使用できます。

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 に答える