JQuery press ENTER event, jquery press ENTER

Source: Internet
Author: User

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;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.