2

为什么有些键码会转换为其他字符?

http://jsfiddle.net/h9268/

我认为 219 应该是 [ 字符。

onKeyPress I get 91
onKeyDown I get 219

火狐,测试页面:http ://www.asquare.net/javascript/tests/KeyCode.html

更新:混淆是由 onKeyPress 和 onKeyDown 事件的键码产生的。onKeyPress 返回字符码(91),onKeyDown 返回键码(219)。

此表同时显示 ascii 代码和密钥代码(按浏览器)。http://unixpapa.com/js/key.html

4

3 回答 3

2

That's for Unicode. It's taking the Unicode values and converting it to Unicode characters.

于 2012-09-04T09:44:22.693 回答
1

它转换为 Unicode,这里是转换表,请改用 91

于 2012-09-04T09:44:43.293 回答
0

W3Schools says:

Definition and Usage

The fromCharCode() method converts Unicode values into characters.

Note: This is a static method of the String object, and the syntax is always String.fromCharCode().

Instead of 219 must be 91 for [ character

219 means for keyCode not charCode

于 2012-09-04T09:44:29.537 回答