【问题标题】:Form with multiple submit具有多个提交的表单
【发布时间】:2017-09-12 13:21:37
【问题描述】:

我有一个包含多个提交的表单。如何找到提交的按钮?

$("#my_form").live("submit", function(event) {

    event.preventDefault();

    var form_action = $(this).attr("action");
    var form_data   = $(this).serialize();
    // Bonton ?

    $.post(
        // ...
    );
    return false;
});

【问题讨论】:

  • 你到底在问什么?附上的代码 sn -p 真的没有多大意义。
  • 从 jQuery 1.7 开始,.live() 方法已被弃用。使用.on() 附加事件处理程序.. 参考api.jquery.com/live
  • 我们使用的是 JQuery 1.8.2 =)
  • on() 不起作用。$("#my_form").on("submit", function(event) { ... }

标签: jquery ajax forms submit live


【解决方案1】:

您可以使用事件参数来验证它

$("#my_form").live("submit", function(event) {

event.preventDefault();

var form_action = $(this).attr("action");
var form_data   = $(this).serialize();
// Bonton ?

$.post(
    // ...
);
console.log($(event.target)); // this button was clicked


return false;

});

【讨论】:

  • 我会试试的。我第一次使用javascript。
  • 我找到了这个 ==> var btn = $(this).find(":submit")
  • 或者这个:$(document.activeElement)
猜你喜欢
  • 2016-01-20
  • 1970-01-01
  • 2012-01-29
  • 2018-04-08
  • 1970-01-01
  • 1970-01-01
  • 2019-07-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多