在 jQuery 中克隆表单并增加索引
这看起来相对简单,我只是被 jQuery 语法难住了。
基本上我想采用这种形式:
<div class="me_signup">
<input type="text" name="referral[0][name]" id="referral_0_name">
<br>
<input type="text" name="referral[0][email]" id="referral_0_email">
</div>
并用按钮复制它并增加变量数..
$(".add_another_button").click(function(){
...
};
This seems relatively simple, I'm just stumped on jQuery syntax.
Basically I want to take this form :
<div class="me_signup">
<input type="text" name="referral[0][name]" id="referral_0_name">
<br>
<input type="text" name="referral[0][email]" id="referral_0_email">
</div>
And duplicate it with a button and increase the variable number..
$(".add_another_button").click(function(){
...
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这个之类的东西?
Something like this?
您可以将所有 html 放入一个变量中,并使用 .append() 方法将其添加到特定的 DOM 元素。而且,如果您克隆它,请务必将“id”更改为“class”,因为 id 在每个页面上必须是唯一的。
官方文档中有关 .append() 的更多信息
You can put all that html in a variable, and use .append() method to add this to a particular DOM element. And, should you clone this, be sure to change "id" to "class", because id must be unique on each page.
Some more about .append() in official documentation