JQuery response to the implementation of the enter key

  • 2020-03-30 02:40:32
  • OfStack

Sometimes we have the requirement that when the user finishes the data in the form, they can press the enter key to perform the query or save operation. The idea is as follows.

Place your form form or area that needs to respond to the enter key between divs. Like:
<div class="top_inputbox"> 

 Company name: <input class="inp" type="text" name="qureyBean.com_name" 
value="${qureyBean.com_name}" /> 

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


Js in response to the keyboard enter key:
$(".top_inputbox").keypress(function (e){ 
var code = event.keyCode; 
if (13 == code) { 
alert(" keyboard-responsive enter The event "); 

So you can alert to do what you want to do.

The company is currently using this response:
//Press 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(" keyboard-responsive enter The event "); 

I did an Internet search. E.k. eyCode? E.k eyCode: e.w hich? This is for compatibility.

Related articles: