我正在使用以下代码:
$('.game-list-right-bottom > .game-list-file').each(function(i) {
if( i % 4 == 0 ) {
$(this).nextAll().andSelf().slice(0,4).wrapAll('<div class="game-list-files"></div>');
}
});
转这个:
<div class="game-list-right-bottom">
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
进入这个:
<div class="game-list-right-bottom">
<div class="game-list-files">
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
<div class="game-list-files">
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
</div>
(基本上.game-list-files
每四个 .game-list-file 包装一个)。
问题是我有不止一个.game-list-right-bottom
:
<div class="game-list-right-bottom">
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
<div class="game-list-right-bottom">
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
所以它最终是这样的:
<div class="game-list-right-bottom">
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
<div class="game-list-right-bottom">
<div class="game-list-file"></div>
<div class="game-list-files">
<div class="game-list-file"></div>
</div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
<div class="game-list-file"></div>
</div>
我想将该 jQuery 代码单独应用于每个.game-list-right-bottom
. 如何存档?