【发布时间】:2009-04-17 03:57:14
【问题描述】:
假设我有 5 个强元素,我想使用 jQuery 将它们包装在 div 元素中,以 2 个为一组。
例子:
<!--original markup-->
<strong>I AM STRONG</strong>
<strong>I AM STRONG</strong>
<strong>I AM STRONG</strong>
<strong>I AM STRONG</strong>
<strong>I AM STRONG</strong>
变成
<!-- new markup -->
<div>
<strong>I AM STRONG</strong>
<strong>I AM STRONG</strong>
</div>
<div>
<strong>I AM STRONG</strong>
<strong>I AM STRONG</strong>
</div><div>
<strong>I AM STRONG</strong>
</div>
最好的方法是什么?我尝试了一些事情,但它们有问题。强元素不能有固定的高度。此外,这些元素仅作为示例。
我将如何编写一个 jQuery 循环来做到这一点?
谢谢
编辑 没有固定数量的元素。
【问题讨论】:
标签: javascript jquery loops