【发布时间】:2018-01-14 22:33:34
【问题描述】:
我正在处理 HTML 输入过滤,我有以下情况:
我需要将 keyCodes 转换为字符,但是当我处理 Numpad 键时,我得到了奇怪的结果:
String.fromCharCode(96) //should be 0 but I recieve "`"
String.fromCharCode(97) //should be 1 but I recieve "a"
String.fromCharCode(98) //should be 2 but I receive "b"
String.fromCharCode(99) //should be 3 but I recieve "c"
String.fromCharCode(100) //should be 4 but I recieve "d"
String.fromCharCode(101) //should be 5 but I recieve "e"
String.fromCharCode(102) //should be 6 but I recieve "f"
String.fromCharCode(103) //should be 7 but I recieve "g"
从文档和事件调试中,我可以看到以下映射:
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
链接:https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
我在这里错过了什么?
【问题讨论】:
-
请出示您正在使用的minimal reproducible example 代码,这样我们可以更轻松地为您提供有效的答案。
-
什么最小、完整和可验证的例子?只需执行 String.fromCharCode(103) 即可获得示例
标签: javascript keycode