jQuery up键/向下键按键检测不起作用? [英] jQuery up key / down key keypress detection not working?
本文介绍了jQuery up键/向下键按键检测不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下代码中:
$(document).keypress(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 40) {
alert("down pressed");
} else if (code == 38) {
alert("up pressed");
}
});
我正在尝试检测是否按下了向下键或向上键。为什么不工作?
I'm trying to detect if the down key or up key is pressed. Why isn't it working?
小提琴
http://jsfiddle.net/K9uDn/10/
我在使用chrome
I'm in chrome
推荐答案
使用 keydown 而非按键,某些浏览器在特殊键时不会触发按键 (如箭头所示)按下
Use keydown instead of keypress, some browsers does not fire keypress when an "special key (like arrows)" are pressed
这篇关于jQuery up键/向下键按键检测不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文