JQuery press ENTER event, jquery press ENTER
Write down jquery's carriage return event
Global:
$ (Function (){
Document. onkeydown = function (e ){
Var ev = document. all? Window. event: e;
If (ev. keyCode = 13 ){
$ ('# FormId). submit (); // process the event
}
}
});
A control:
$ ('# Id'). keydown (function (e ){
If (e. keyCode = 13 ){
$ ('# FormId). submit (); // process the event
}
});
If (window. event. keyCode = 13) window. event. keyCode = 0 // then the Enter key is canceled.
If you want to simulate the Tab key, you just need to write it as if (window. event. keyCode = 13) window. event. keyCode = 9, and it will jump to another element.
Source: more white ----> https://www.cnblogs.com/wenbo/archive/2011/08/20/2147014.html;
Self-implemented code:
<Script>
Var verifyCode = new GVerify ("v_container ");
$ (). Ready (function (){
$ ("# LoginName"). focus (); // The default login name input gets the focus
// Press Enter when the focus is obtained
// Login name input
$ ("# LoginName"). keydown (function (e ){
If (e. keyCode = 13)
{
LonginLoad ();
}
});
// Password input
$ ("# LoginPwd"). keydown (function (e ){
If (e. keyCode = 13 ){
LonginLoad ();
}
});
// Verification Code input
$ ("# Code"). keydown (function (e ){
If (e. keyCode = 13 ){
LonginLoad ();
}
});
// Remember the login information input
$ ("# Jizhuwo"). keydown (function (e ){
If (e. keyCode = 13 ){
LonginLoad ();
}
});
// Press Enter when the focus is obtained (complete)
// Click
$ ("# Login"). click (function (){
LonginLoad ();
});
})
// Determine the verification code to log on, and determine whether to submit the logon code
Function LonginLoad (){
Var code = $ ("# Code"). val ();
Var res = verifyCode. validate ($ ("# Code"). val ());
Var loginName = $ ("# loginName"). val ();
Var loginPwd = $ ("# loginPwd"). val ();
If (loginName = ""){
Layer. msg ('enter the user name! ', {Icon: 6 });
Return;
}
If (loginPwd = ""){
Layer. msg ('enter the password! ', {Icon: 6 });
Return;
}
If (code = ""){
Layer. msg ('enter the verification code! ', {Icon: 6 });
Return;
}
Else {
If (res ){
// Perform the logon operation
Layer. msg ("Logon successful! Welcome back ", {icon: 6 });
SetTimeout (Jump, 700); // delayed Logon
} Else {
Layer. msg ('verification code input error! ', {Icon: 5 });
$ ("# LoginPwd"). val ("");
$ ("# Code"). val ("");
}
}
}
// Jump to the page after success
Function Jump (){
Window. location. href = "/MainInterface/Index ";
}
</Script>
If you encounter a problem in one or two attempts, you cannot use the carriage return event after loading without focus. You have searched the internet and have no specific answers.
Finally, I thought about this solution, which is a good solution for myself;