JS/jQuery中的绑定箭头键如何将函数绑定到Javascript和/或jQuery中的左右箭头键?我查看了jQuery的js热键插件(包装内置的绑定函数以添加参数以识别特定的键),但它似乎不支持箭头键。
3 回答
喵喵时光机
TA贡献1846条经验 获得超7个赞
$(document).keydown(function(e) {
switch(e.which) {
case 37: // left
break;
case 38: // up
break;
case 39: // right
break;
case 40: // down
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)});casebreak
e.which
document.onkeydown = function(e) {
e = e || window.event;
switch(e.which || e.keyCode) {e.keye.whiche.keyCodee.key'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'
30秒到达战场
TA贡献1828条经验 获得超6个赞
$(document).keydown(function(e){
if (e.which == 37) {
alert("left pressed");
return false;
}});
37-左
38岁以上
39-权利
四十下
添加回答
举报
0/150
提交
取消
