2012-09-04 47 views
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

是不是'91'? – VisioN

+0

视觉有权利,必须是'91'而不是219 –

+0

这里是一个测试页面http://www.asquare.net/javascript/tests/KeyCode.html – danidacar

回答

2

这是为Unicode。它采用Unicode值并将其转换为Unicode字符。

0

W3Schools的说:

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(). 

相反的219必须91[字符

219装置的keyCode不是则charCode

1

它转换成Unicode,这里是Here是转换表,使用91代替