jQuery 多种表单和表单插件
我有一个如下所示的 html,其中有多种形式。我使用 JSTL 生成此值,因此该数字可能会根据我的数据库中注册的内容而有所不同。每个表单都有自己的提交按钮。
基本上,我想使用表单插件 ajax 提交按钮,但我不知道如何引用表单。
<form id="form-1" action="approve.htm">
<textarea name="comment"> </textarea>
<input type="submit" value="Add Comment" />
</form>
<form id="form-2" action="approve.htm">
<textarea name="comment"> </textarea>
<input type="submit" value="Add Comment" />
</form>
.
.
.
<form id="form-10" action="approve.htm">
<textarea name="comment"> </textarea>
<input type="submit" value="Add Comment" />
</form>
我的问题是如何知道使用 jQuery 提交了哪个表单 id。
我不知道将在对 ajax 表单的调用中放置哪个表单名称。
$('#form-name?').ajaxForm();
I have a html like below wherein there are multiple forms. I generate this using JSTL, so the number could vary depending on what is enrolled in my DB. Each form has its own submit button.
Basically, I wanted to use the Form Plugins ajax submit button, but I don't know how to reference the form.
<form id="form-1" action="approve.htm">
<textarea name="comment"> </textarea>
<input type="submit" value="Add Comment" />
</form>
<form id="form-2" action="approve.htm">
<textarea name="comment"> </textarea>
<input type="submit" value="Add Comment" />
</form>
.
.
.
<form id="form-10" action="approve.htm">
<textarea name="comment"> </textarea>
<input type="submit" value="Add Comment" />
</form>
My problem is how do I know which form id is getting submitted by using jQuery.
I don't know which form-name will I place in the call to the ajax form.
$('#form-name?').ajaxForm();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,它会提交当前表单,例如您在其中单击“添加评论”的表单,因此只需按标签名称选择它们:
或者(特别是如果有其他页面上的表单),给它们一个类,例如:
并按类选择:
重要的是要记住
.ajaxForm()
不会发送By default it'll submit the current form, e.g. the one you clicked "Add Comment" in, so just select them by tag name:
Alternatively (especially if there are other forms on the page), give them a class, for example:
And select by class:
It's important to keep in mind that
.ajaxForm()
doesn't send the<form>
it prepares it. You're just selecting some forms and preparing them...they all still submit individually. So all you need to do here is use a selector that selects only the forms you want to prepare to submit through AJAX.