动态添加/删除表单的新输入
所以我是一个初学者,正如标题所说,我希望能够;单击按钮后,允许用户向我的表单添加另一个输入字段。我也希望能够删除这个。
该表格的用途是将学生添加到学生组中,然后我将其存储在我的数据库中。
我的表单示例:
<form name="addstudents" id="addstudents" method="post" action="add_students.php">
<table><tr><td>Student:</td><td>
<input type='text' name="1" size='20'></td><td><input type="button" id="add" value="+">
</td><td><input type="button" id="remove" value="-"></td>
</table></form>
但是,从我一直在查看的内容来看,有不同的建议,例如使用clone()函数或Jqueryappendto()。
这样做的最佳方法是什么?
谢谢
So I am a beginner and as the title says I want to be able to; on the click of a button, allow the user to add another input field to my form. I would also like to be able to remove this.
The use of the form is adding students to a student group, which I will then be storing in my database.
my form example:
<form name="addstudents" id="addstudents" method="post" action="add_students.php">
<table><tr><td>Student:</td><td>
<input type='text' name="1" size='20'></td><td><input type="button" id="add" value="+">
</td><td><input type="button" id="remove" value="-"></td>
</table></form>
However from what I have been looking at there are different suggestions such as using a clone() function or Jquery appendto().
which is the best method for doing so?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请记住,您还可以从表单中删除任何 DOM,只需找到适当的 jquery 选择器,
检查此工作示例,该示例是在jsfiddle.net 来帮助您解决此问题
Remember you also can remove any DOM from your form just find the appropiate jquery selector
check this working sample that a made on jsfiddle.net to help you with this
我会使用 JavaScript,我已经在此处回答了这个问题。只需使用纯 JavaScript 来编辑页面的 HTML。希望这有帮助!
I would use JavaScript, I already answered this question here. Just uses plain JavaScript to edit the HTML of the page. Hope this helps!