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.