且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery提交带有2个提交按钮的Ajax表单

更新时间:2022-12-11 13:32:17

您可以将事件处理程序放在按钮上而不是窗体上.从表单中获取参数,然后为按钮添加参数,然后发布表单.确保处理程序返回"false".

You could put the event handler on the buttons instead of on the form. Get the parameters from the form, and then add a parameter for the button, and post the form. Make sure the handler returns "false".

$(function() {
  $('input[name=sub]').click(function(){
    var _data= $('#form_1').serialize() + '&sub=' + $(this).val();
    $.ajax({
      type: 'POST',
      url: "php.php?",
      data:_data,
      success: function(html){
         $('div#1').html(html);
      }
    });
    return false;
  });
});

您必须显式添加"sub"参数,因为当您调用"serialize()"时,jQuery不包含那些参数.

You have to explicitly add the "sub" parameter because jQuery doesn't include those when you call "serialize()".