Javascript 如何使用jQuery包装内容?

Javascript 如何使用jQuery包装内容?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何使用jQuery使用占位符div环绕内容 所以我可以把这个转过来: 用jQuery 1.4试试这个: $('.placeholder').each(function(){ $(this).nextUntil('.placeholder').andSelf().wrapAll('<div class="wrap" />'); }); $('.placeholder')。每个(函数(){ $(this.nextUntil('.placeholder')。和self().

如何使用jQuery使用占位符div环绕内容

所以我可以把这个转过来:


用jQuery 1.4试试这个:

$('.placeholder').each(function(){
     $(this).nextUntil('.placeholder').andSelf().wrapAll('<div class="wrap" />');
});
$('.placeholder')。每个(函数(){
$(this.nextUntil('.placeholder')。和self().wrapAll('');
});

jQuery 1.4添加了nextuntil函数

更加具体:是否希望它使用类“placeholder”将所有div元素包装到div?如果没有更多的“占位符”div,那么是否要包装所有div?还是要包装每3个HTML元素?你的问题有太多的解释…不是每三个元素,可能有任何数量。唯一的变量是将有一个占位符标记。我修改了这个例子使它更清楚