0
我有一個有點分組系統,其中兩個div之間的所有元素被分組在一起。請參見下面的代碼,看看我想說:jQuery:wrapAll但單獨的元素集?
$(document).ready(function(){
var groupo = $('div').filter(function(){return $(this).text().match(/\[group\]/)}); //finds "[group]"
var groupc = $('div').filter(function(){return $(this).text().match(/\[\/group\]/)}); //finds "[/group]"
groupc.addClass("groupclose"); //adds the class groupclose so that it can be used by nextUntil
groupo.nextUntil(".groupclose").wrapAll('<div class="group"></div>');
groupo.remove();
groupc.remove();
});
當HTML是:
<div>[group]</div>
<div>first</div>
<div>second</div>
<div>[/group]</div>
它工作得很好,但是當有兩個或更多的「羣體」的wrapAll包裝在一起,例如:
<div>[group]</div>
<div>first</div>
<div>second</div>
<div>[/group]</div>
<div>[group]</div>
<div>this is in</div>
<div>another group</div>
<div>which get wrapped together with the one above</div>
<div>[/group]</div>
的問題與此類似wrapAll jQuery problem但在這種情況下,我們知道的div的數量在一組,而在這種情況下,我們不知道。
任何想法?
編輯:添加鏈接jsbin http://jsbin.com/ejepu3
太神奇了!謝謝! :d – Warrantica 2011-01-13 14:54:15