Contents:
.on( "submit" [, eventData ], handler )Returns: jQuery
Description: Bind an event handler to the "submit" event.
-
version added: 1.7.on( "submit" [, eventData ], handler )
submit
event. For the deprecated .submit()
method, see .submit()
.
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.
1
2
3
4
5
6
7
|
|
1
2
3
4
|
|
.preventDefault()
on the event object or by returning false
from our handler. We can trigger the event manually when another element is clicked:
1
2
3
|
|
submit
action on the form will be fired, so the form will be submitted.
submit
event does not bubble in Internet Explorer. However, scripts that rely on event delegation with the submit
event will work consistently across browsers as of jQuery 1.4, which has normalized the event's behavior.
Additional Notes:
-
Forms and their child elements should not use input names or ids that conflict with properties of a form, such as
submit
,length
, ormethod
. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see DOMLint<.
Examples:
Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
|
Demo:
Example 2
1
2
3
|
|
Example 3
1
|
|
.trigger( "submit" )Returns: jQuery
Description: Trigger the "submit" event on an element.
-
version added: 1.0.trigger( "submit" )
-
"submit"Type: stringThe string
"submit"
.
-
.on( "submit", ... )
.