如何在jquery中获取右,左,上和下箭头键值 [英] How to get right, left, up and bottom arrow key value in jquery
本文介绍了如何在jquery中获取右,左,上和下箭头键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了以下代码,每当点击箭头键(左,右,上,下)时,我得到的键值为0。有人可以提供帮助吗?
I have used the below code, and whenever click the arrow key(left, right, up, down) i get the key value is "0". anyone can help on this?
$(document).keypress(function (e) {
alert("key value: " + e.which);
});
按键时如何获得(向上,向下,向右,向左)箭头键值。
How to get (Up, Down, Right, Left) arrow key value when keypress.
推荐答案
使用 keydown
投入 keypress
$(document).keydown(function(event){
var key = event.which;
switch(key) {
case 37:
// Key left.
break;
case 38:
// Key up.
break;
case 39:
// Key right.
break;
case 40:
// Key down.
break;
}
});
这篇关于如何在jquery中获取右,左,上和下箭头键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文