Home >Web Front-end >JS Tutorial >jquery sample code to get keycode_jquery

jquery sample code to get keycode_jquery

WBOY
WBOYOriginal
2016-05-16 17:06:12975browse

As shown below:

Copy code The code is as follows:

txtSearch: Text box ID

$("#txtSearch").keyup(function (event) {
var keycode = event.which;
if (keycode == 13) {
alert('You have pressed return Car key');

}

});

or

xObj.keyup(function(event){
//Get the key value of the current key
//There is a which attribute on the jQuery event object to get the key value of the keyboard key
var keycode = event.which;
//Handling carriage return
if(keycode==13){

}
//Handling esc
if(keycode == 27){

                                                                                         🎜> //There is a which attribute on the jQuery event object to get the key value of the keyboard key
var keycode = event.which;
//Handle the carriage return situation
if(keycode==13 ){

}
//Handling esc
if(keycode == 27){

}
}
}); >

Statement:
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