To capture key press event in jQuery we can have key press event and then we can get code of key which is pressed.
Below are few key codes
Enter : 13
Esc : 27
Space: 32
Tab : 9
check here for all key codes
Below example will handle the enter and esc key press event using jquery :
Click to see demo in jsfiddle.
Below are few key codes
Enter : 13
Esc : 27
Space: 32
Tab : 9
check here for all key codes
Below example will handle the enter and esc key press event using jquery :
$('#textarea').keyup(function(event){
//use event.which in firefox
var keycode = (event.keyCode ? event.keyCode : event.which);
alert("Key code for pressed key "+keycode);
//enter pressed
if(keycode == '13'){
//perform enter key press operation on textarea
}
//esc pressed
if(keycode == '27'){
//perform esc key press operation on textarea
}
});
//use event.which in firefox
var keycode = (event.keyCode ? event.keyCode : event.which);
alert("Key code for pressed key "+keycode);
//enter pressed
if(keycode == '13'){
//perform enter key press operation on textarea
}
//esc pressed
if(keycode == '27'){
//perform esc key press operation on textarea
}
});
Click to see demo in jsfiddle.
No comments:
Post a Comment