如何使用jQuery使用占位符div来包装内容?
所以我可以这样说:
<div class="placeholder"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="placeholder"></div>
<div class="content"></div>
<div class="content"></div>
<div class="placeholder"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="placeholder"></div>
进入:
<div class="wrap">
<div class="placeholder"></div>
<div class="content">Abcd</div>
<div class="content">Abcd</div>
<div class="content">Abcd</div>
<div class="content">Abcd</div>
</div>
<div class="wrap">
<div class="placeholder"></div>
<div class="content">Abcd</div>
<div class="content">Abcd</div>
</div>
<div class="wrap">
<div class="placeholder"></div>
<div class="content">Abcd</div>
<div class="content">Abcd</div>
<div class="content">Abcd</div>
</div>
尝试使用jQuery 1.4:
$('.placeholder').each(function(){
$(this).nextUntil('.placeholder').andSelf().wrapAll('<div class="wrap" />');
});
jQuery 1.4添加了nextUntill函数