逐个克隆div并重命名元素ID [英] Clone div and rename element ids incrementally

查看:135
本文介绍了逐个克隆div并重命名元素ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,让我们说,我有div里面的表单元素。我希望能够使用jQuery按钮单击克隆该div,并添加表单的第2版,因此所有元素ID都将在其名称中加1。

 < div id =card> 
<! - 第1部分 - >
< h1 class =card_build>建立您的卡片选项:< / h1>

< option value => - 选择塑料 - < / option>
< / select>

< select id =UG_tippingname =UG_tipping []>
< option value => - 选择UG / Tipping - < / option>
< / select>
<! - 第1部分 - >
<! - 第2部分 - >
< div id =part2style =margin-top:10px;>
< h1 class =card_build>自订卡片:< / h1>
< input type =textname =3rdLinesize =32class =fieldid =3rdLine>
< input type =textname =4thLinesize =32class =fieldid =4thLine>
< input type =textname =card_valuesize =32class =fieldid =card_value>
< label for =showpoints>显示Points?< / label>
< input type =checkboxvalue =pointsclass =checkboxchecked =checked>
< label for =cobrand>联名?< / label>
< input type =checkboxvalue =cobrandclass =checkboxchecked =checked>