【问题标题】:jQuery multiple forms and Form pluginjQuery 多表单和表单插件
【发布时间】:2010-07-17 16:07:51
【问题描述】:

我有一个如下所示的 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();

【问题讨论】:

    标签: jquery jquery-plugins jquery-selectors jquery-forms-plugin


    【解决方案1】:

    默认情况下它会提交 current 表单,例如您在其中单击“添加评论”的那个,因此只需按标签名称选择它们:

    $('form').ajaxForm();
    

    或者(特别是如果页面上有其他表单),给它们一个类,例如:

    <form id="form-1" class="commentForm" action="approve.htm">
    

    并按类选择:

    $('form.commentForm').ajaxForm();
    

    重要的是要记住.ajaxForm() 不会发送 &lt;form&gt;准备它。您只是选择一些表格并准备它们……它们仍然单独提交。因此,您需要在这里做的就是使用一个选择器,该选择器只选择您希望准备通过 AJAX 提交的表单。

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多