Javascript code for the carriage return key trigger event in the text box [multi-browser compatibility] _ javascript skills

Source: Internet
Author: User
After entering the content in the text box, you often need to press enter, focus to jump to the next text box, or trigger the button event to determine whether to press the carriage return is very simple:

The Code is as follows:


Function EnterPress (){
If (event. keyCode = 13 ){
...
}
}


The onkeypress of IE6 accepts the "carriage return event", while the onkeydown does not.
In IE8, onkeypress does not accept the "carriage return event", while onkeydown does.
... You don't have to worry about this. Write both of them.

The Code is as follows:




However, under FF, there will be a conflict. FF is onkeypress and onkeydown both accept the "carriage return event.
At the same time, to be compatible with FF, you need to write as follows:

The Code is as follows:


Function EnterPress (e) {// input the event
Var e = e | window. event;
If (e. keyCode = 13 ){
...
}
}


If you pass the parameter event to any event and do not pass the parameter, you can run FF only once:

The Code is as follows:


&


In summary, compatible with IE and FF:

The Code is as follows:



Script
Function EnterPress (e) {// input the event
Var e = e | window. event;
If (e. keyCode = 13 ){
Document. getElementById ("txtAdd"). focus ();
}
}
Script






-- By: Bubble fantasies
Related Article

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.