【问题标题】:How to submit forms using radio button one at a time如何使用单选按钮一次提交一个表单
【发布时间】:2014-07-06 08:17:08
【问题描述】:

我有多个具有相同 ID、隐藏字段和单选按钮的表单。

<form method='post' id='check'>
    <input type='radio' name='class' value='ac'>
    <input type='hidden' name='train_no' value='12304'>
</form>

我正在使用 jquery ajax 提交表单。

$(document).ready(function(){
    $("input[name='class']").change(function() {                
        $.ajax({
            type: "POST",
            url: "check.php",             
            data: $("#check").serialize(),                
            success: function(response){                    
                $("#responsecontainer").html(response); 
                //alert(response);
            }
        });
    });
});

问题是我无法确定我需要提交哪个表单,因为所有表单的表单 ID 都是相同的。我需要一次提交一份带有表单数据的表单。任何人都可以提出更好的方法吗?

【问题讨论】:

  • 我停止阅读“我有多个具有相同 ID 的表单”你不能,ID 是唯一的 !!
  • 我知道我意识到@adeneo 所以我要求一种更好的方法。
  • 改成data : $(this.form).serialize(),
  • +1 这是一个不错的技巧@adeneo

标签: jquery html ajax forms radio-button


【解决方案1】:
$(function(){
    $("input[name='class']").change(function() { 
        var form = this.form; // Here is your form reference
        $.ajax({
            type: "POST",
            url: "check.php",             
            data: $(form).serialize(),                
            success: function(response){                    
                $("#responsecontainer").html(response); 
                //alert(response);
            }
        });
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-23
    • 2019-07-06
    • 1970-01-01
    • 2017-05-03
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多