1

jQueryを使用して追加<li>したいと思います。<ul>私は次の行でそれを成功させました:

var ChosedItem = $("#chosedItem");
ChosedItem.append('<li id=' + $(this).attr('id') + ' limit=' + $(this).attr('limit') + ' ><span>' + $(this).children(0) + '</span></li>');

この中で、が存在する#chosedItemdividです<ul>

しかし、私の場合の問題は、<li>アイテムにスペースが含まれている場合、[0]thを使用しているため、子の位置の後にスペースが追加されないことですchlidren(0)。複数のスペースを含むアイテムchildren(0)を追加する代わりに何を使用できますか?<li>

4

1 に答える 1

0

これを試して

$('#chosedItem').children().filter(function(){    

  if($(this).text().split(' ').length > 2) //Elements with two or more space will be returned
     return $(this);

}).append('<li id=' + $(this).attr('id') + ' limit=' + $(this).attr('limit') + ' ><span>' + $(this).children(0) + '</span></li>');
于 2012-06-11T10:41:44.003 に答える