问题描述
我有一个允许用户引用朋友的表单。我想在两个输入字段(朋友邮件和朋友姓名)下方添加一个链接,它将一次性克隆朋友信箱并添加到下面。另外,friend email和friend name的name属性是 name =friend_email [0]
和 name =friend_name [ 0]
建议。克隆和增加下标的最佳方法是什么?以下是代码:
I have a form that allows users to refer friends. I want to add a link below the two input fields, "friend email" and "friend name", that will clone "friend-box" one time and add it below. In addition, the name attribute of "friend email" and "friend name" are name="friend_email[0]"
and name="friend_name[0]"
as suggested here. What's the best way to clone and increment the subscript? Here's the code:
<div class="friend-box">
<div class="field">
<span><label for='friend_name'><strong>Friend's Name *</strong></label> </span>
<input id='friend_name' name='friend_name[0]' type='text' />
</div>
<div class="field">
<span><label for='friend_email'><strong>Friend's Email *</strong></label></span>
<input id='friend_email' name='friend_email[0]' type='text' />
</div>
</div>
做这件事的最好方法是什么?例如,我曾经遇到过的一个问题是,当我一次又一次克隆朋友盒子时,它明显克隆了它。所以我猜我需要在那里有一个身份证号码,并增加它。或者,我看到的另一种方法是在页面加载时克隆friend-box,并从内存中克隆它。
What's the best way to do this? One of the problems I had for example, is that when I cloned "friend-box" once and then twice, it obviously cloned it exponentially. So I'm guessing I need to have an ID number in there as well and increment it. Or, which is another method I saw, is to clone the "friend-box" when the page loads and keep cloning it from memory.
谢谢,
Ryan
Thanks,Ryan
推荐答案
我在这里创建了一个示例:
I have created an example here:http://jsfiddle.net/K8hhW/5/
您无需担心递增在括号中的数字,表单自动为你做。
You do not need to worry about incrementing the numbers in the brackets, the form does this automatically for you.
这篇关于用jQuery克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!