How jQuery responds to the enter key

Source: Internet
Author: User

Sometimes we have this requirement: After the user completes the data in the form, press enter to execute the query or save operation. The implementation idea is as follows.

Place your form or area that needs to respond to the enter key between the div. Shape:
Copy codeThe Code is as follows:
<Div class = "top_inputbox">

Unit name: <input class = "Indium" type = "text" name = "qureyBean.com _ name"
Value = "$ {qureyBean.com _ name}"/>

<A href = "javascript: firstPage ();"> query </a>

</Div>

Js responding to the enter key on the keyboard:
Copy codeThe Code is as follows:
$ (". Top_inputbox"). keypress (function (e ){
Var code = event. keyCode;
If (13 = code ){
Alert ("Responding to the enter event on the keyboard ");
}
});

In this way, you can use alert to perform the operations you want.

The company currently uses the following response:
Copy codeThe Code is as follows:
// Enter for quick query
$ (". Top_inputbox"). keypress (function (e ){
Var keyCode = e. keyCode? E. keyCode: e. which? E. which: e. charCode;
If (keyCode = 13 ){
Alert ("Responding to the enter event on the keyboard ");
}
});

I searched the internet, e. keyCode? E. keyCode: e. which? E. which: e. charCode this is for compatibility.

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.