Home > Web Front-end > JS Tutorial > Implementation ideas of jQuery responding to the enter key_jquery

Implementation ideas of jQuery responding to the enter key_jquery

WBOY
Release: 2016-05-16 16:51:56
Original
1092 people have browsed it

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:

Copy code The code is as follows:


Unit name: value="${qureyBean.com_name}" />

Query



JS that responds to the keyboard enter key:
Copy code The code is as follows:

$(".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:
Copy code The code is as follows:

//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.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template