Press ENTER to query (optimize)

Source: Internet
Author: User

External JS file: enterkeysearch.js

$ (function () {Window.onkeyup= function (Event) {        if(Flag &&Event. keycode = = -) {dosubmit (); }      }   varFlag =false; var$querys = $ (". Query");  for(vari =0; I < $querys. length; i++) {      var$query = $ ($querys.Get(i)); $query. Bind ({"Focus": function () {flag=true; },        "Blur": function () {flag=false;   }      }); }});

How to use:

1. After the control gets focus, the keyboard returns the Class property of the HTML control that needs to be queried to add a query, such as class= "Query", class= "Style1 query"

2, the realization Dosubmit method. The Dosubmit method is an action that is performed after a carriage return event, such as a query operation.

Implementation ideas:

1. When the page loads, initialize an identifier flag (this identifier is true to indicate that the HTML tag that supports the ENTER key query has the focus, and false the HTML tag that supports the ENTER key query does not get the focus),

Remove all HTML tags from the class= "query" and iterate through the add focus and blur events to each HTML tag being fetched.

Bind window to onkeyup Event

2. When the label of class= "query" gets the focus, flag is set to true, and flag is set to False when the focus is lost

3, when the keyboard is pressed, will determine whether it is the ENTER key (enter key KeyCode is 13), if it is the ENTER key, and flag is true, that is, get the focus, you will call the Dosubmit method

4, in the Dosubmit method to do some of the custom operations

Press ENTER to query (optimize)

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: 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.