📌  相关文章
📜  javascript 检测箭头键按下 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:14.900000             🧑  作者: Mango

代码示例1
//detecting arrow key presses
document.addEventListener('keydown', function(e) {
    switch (e.keyCode) {
        case 37:
            alert('left');
            break;
        case 38:
           alert('up');
            break;
        case 39:
            alert('right');
            break;
        case 40:
            alert('down');
            break;
    }
});