LoginSignup
6
4

More than 5 years have passed since last update.

jQueryでformのsubmitをフックして独自の処理を差し込む

Posted at
hoge.coffee
$("#form").on "submit", (event) ->
  # 何か処理
  this.submit

ミソは this.submit している箇所、ここが $("#form").submitだと、このイベントハンドラ自身が再度呼びだされて無限ループにハマる。

this は Form オブジェクトを指している(生のDOMオブジェクト)、本来の submit メソッドはイベントハンドラの呼び出しは行われないが、jQueryの submit メソッドはイベントハンドらを呼び出しているらしい。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4