js 键盘码对应表
js 键盘码对应表
楠木楠 发表于12个月前
js 键盘码对应表
  • 发表于 12个月前
  • 阅读 15
  • 收藏 0
  • 点赞 0
  • 评论 0
摘要: js获取键盘按键的键码event.keyCode,记录-方便查找

1、键盘各按键对应的数字

  • keycode 8 = BackSpace
  • keycode 9 = Tab
  • keycode 12 = Clear
  • keycode 13 = Enter
  • keycode 16 = Shift
  • keycode 17 = Control
  • keycode 18 = Alt
  • keycode 19 = Pause
  • keycode 20 = CapsLock
  • keycode 27 = Escape
  • keycode 32 = Space
  • keycode 33 = Prior
  • keycode 34 = Next
  • keycode 35 = End
  • keycode 36 = Home
  • keycode 37 = Left
  • keycode 38 = Up
  • keycode 39 = Right
  • keycode 40 = Down
  • keycode 41 = Select
  • keycode 42 = Print
  • keycode 43 = Execute
  • keycode 45 = Insert
  • keycode 46 = Delete
  • keycode 47 = Help
  • keycode 48 = 0
  • keycode 49 = 1
  • keycode 50 = 2
  • keycode 51 = 3
  • keycode 52 = 4
  • keycode 53 = 5
  • keycode 54 = 6
  • keycode 55 = 7
  • keycode 56 = 8
  • keycode 57 = 9
  • keycode 65 = A
  • keycode 66 = B
  • keycode 67 = C
  • keycode 68 = D
  • keycode 69 = E
  • keycode 70 = F
  • keycode 71 = G
  • keycode 72 = H
  • keycode 73 = I
  • keycode 74 = J
  • keycode 75 = K
  • keycode 76 = L
  • keycode 77 = M
  • keycode 78 = N
  • keycode 79 = O
  • keycode 80 = P
  • keycode 81 = Q
  • keycode 82 = R
  • keycode 83 = S
  • keycode 84 = T
  • keycode 85 = U
  • keycode 86 = V
  • keycode 87 = W
  • keycode 88 = X
  • keycode 89 = Y
  • keycode 90 = Z
  • keycode 112 = F1
  • keycode 113 = F2
  • keycode 114 = F3
  • keycode 115 = F4
  • keycode 116 = F5
  • keycode 117 = F6
  • keycode 118 = F7
  • keycode 119 = F8
  • keycode 120 = F9
  • keycode 121 = F10
  • keycode 122 = F11
  • keycode 123 = F12

2、键盘码使用

2.1、原生js使用

document.onkeyup = function (event) {
    var e = event ? event : window.event;
    if (e.keyCode == 13) {//旧版火狐、Opera请使用e.which
        alert('您按了回车键。');
    }
};

2.2、jQuery使用

$(document).on('keyup',function(event){
    if (event.keyCode == 13) {
        alert('您按了回车键。');
    }
});

 

标签: JavaScript
共有 人打赏支持
粉丝 98
博文 472
码字总数 534361
×
楠木楠
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: