1

考虑以下代码:

HTML

<a href='#' id='the-button'>Submit</a>

JavaScript

$("#the-button").click(function(e) {
  e.preventDefault();
  $("#the-form").submit();
});

$("#the-form").submit(function(e) {
  //stuff here
});

单击“#the-button”并提交表单时,不会触发“提交”事件处理程序。有没有办法将事件处理程序附加到表单,以便即使它没有通过提交按钮提交,它也会触发?

4

1 回答 1

4

更改$("#the-form").submit();$("#the-form").trigger('submit');

编辑:但是,就像@wirey 所说,您发布的代码应该可以工作,除非有其他代码干扰。

于 2012-12-05T18:49:54.660 回答