This article introduces you to the user entered the information directly after the return of the form submitted to the jquery implementation method, there is a need to know friends can come in for reference.
There are 3 keyboard events:
jquery Keyboard Event Reference:
1, KeyDown ()
The KeyDown event is triggered when the keyboard is pressed.
2, KeyUp ()
The KeyUp event triggers when the key is released, which is what happens when you press the keyboard
3, KeyPress ()
The KeyPress event triggers when the keystroke is hit, which we can understand to press and lift the same key
The correct code is:
$ (document). KeyUp (function (event) {
if (Event.keycode ==13) {
$ ("#submit"). Trigger ("click");
}
);
Recommended: KeyUp, to prevent the notebook keyboard accidentally touch the
1. Some documents are written in this way:
$ (window). KeyDown (function () {
...
} )
XP system IE6 is unsuccessful.
2. There is also the input
$ ("input"). KeyDown (function () {
...
} )
In this case, the keyboard event can only be heard when input gets the focus.
The example form is as follows:
<form name= "LoginForm" id= "LoginForm" method= "POST" >
<div>
<p> user name: <input type= "Text" Name= "username"/></p>
<p> Password: <input type= "password" name= "password"/></p>
< P><input type= "button" value= "" class= "log_btn"/></p>
</div>
</form>
Juqery Implementation Method:
$ ("#loginform"). KeyDown (function (e) {
var e = e | | event,
keycode = E.which | | e.keycode;
if (keycode==13) {
$ (". Log_btn"). Trigger ("click");
}
);
The above jquery press ENTER to implement form submission Simple example is small series to share all the content, hope to give you a reference, also hope that we support cloud habitat community.