Sometimes we have such a need: when the user completes the data in the form, he can perform the query or save operation by pressing the enter key. The implementation idea is as follows.
Let your form or the area that needs to respond to the enter key be between divs. Shape like:
JS that responds to the keyboard enter key:
$(".top_inputbox").keypress(function ( e){
var code = event.keyCode;
if (13 == code) {
alert("Response to keyboard enter event");
}
});
This way you can alert and do the operations you want to do.
The company currently uses this response:
//Enter quick query
$(".top_inputbox").keypress(function (e) {
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e .charCode;
if (keyCode == 13){
alert("Response to the enter event of the keyboard");
}
});
I am online After searching, e.keyCode ? e.keyCode : e.which ? e.which : e.charCode This is for compatibility.