一个郁闷了好久的错误:

<form method="get">
<input type="text" name="search" />
</form>

$("#submit").submit(function(){
 alert("hello");

return false;

});

问题是无论点击多次次,都不会运行.在官网找到了答案:

.submit( )

This method is a shortcut for .on('submit', handler) in the first variation, and .trigger('submit') in the third.

The submit event is sent to an element when the user is attempting to submit a form. It can only be attached to <form>elements. Forms can be submitted either by clicking an explicit <input type="submit"><input type="image">, or<button type="submit">, or by pressing Enter when certain form elements have focus.

Depending on the browser, the Enter key may only cause a form submission if the form has exactly one text field, or only when there is a submit button present. The interface should not rely on a particular behavior for this key unless the issue is forced by observing the keypress event for presses of the Enter key.

官网已经说的很清楚了,这个.submit只能用于form元素,而不能用于submit,button等。

改为$("form").submit 后就ok了。

 

 

相关文章:

  • 2022-02-07
  • 2022-02-14
  • 2021-06-24
  • 2021-12-27
  • 2021-05-21
  • 2022-01-20
  • 2022-12-23
  • 2021-04-09
猜你喜欢
  • 2021-10-21
  • 2022-03-01
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案