我注意到当我听到按键时,字符代码在 Chrome 和 IE 中的显示方式不同。有谁知道为什么会这样?
铬合金:
numpad key: 0, String.fromCharCode(48) => "0"
numpad key: 1, String.fromCharCode(49) => "1"
numpad key: 2, String.fromCharCode(50) => "2"
numpad key: 3, String.fromCharCode(51) => "3"
numpad key: 4, String.fromCharCode(52) => "4"
numpad key: 5, String.fromCharCode(53) => "5"
numpad key: 6, String.fromCharCode(54) => "6"
numpad key: 7, String.fromCharCode(55) => "7"
numpad key: 8, String.fromCharCode(56) => "8"
numpad key: 9, String.fromCharCode(57) => "9"
IE:
numpad key: 0, String.fromCharCode(96) => "`"
numpad key: 1, String.fromCharCode(97) => "a"
numpad key: 2, String.fromCharCode(98) => "b"
numpad key: 3, String.fromCharCode(99) => "c"
numpad key: 4, String.fromCharCode(100) => "d"
numpad key: 5, String.fromCharCode(101) => "e"
numpad key: 6, String.fromCharCode(102) => "f"
numpad key: 7, String.fromCharCode(103) => "g"
numpad key: 8, String.fromCharCode(104) => "h"
numpad key: 9, String.fromCharCode(105) => "i"
我正在使用应该规范化的 jqueryevent.keyCode
和event.charCode
:
$("#input").keypress(function(e){
console.log e.which, String.fromCharCode(e.which)
})
这与此答案不同,因为它使用香草 javascripte.keyCode
而不是 jquerye.which
我想知道这是否与使用 Windows 虚拟机(Parallels Desktop)有关。