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)