iPad, JavaScript character codes, and shiftKey

牧云@^-^@ 提交于 2019-12-21 04:43:18

问题


Say I have a web application that calls the following jQuery every time a user presses a key in a textarea with an ID of "txt":

$('#txt').keydown(function(e) {
console.log(e.which); // shows the keyCode
console.log(e.shiftKey);
}

On a desktop browser, for characters like ( and 9, I can distinguish between the two by checking to see if the shift key is held down (with e.shiftKey). However, in Safari for iPad, there is no shift key required to type those characters. So, for example, pressing both ( and 9 on the iPad's keyboard logs "57" in the console for the keyCode. The value logged for e.shiftKey always appears to be false.

How might I be able to reliably distinguish between typing shifted characters on the iPad? Thanks in advance!


回答1:


You could try using keyPress. at keyDown both 9 and ( have 57 but at keyPress event they have 9 : 57 and ( : 40.

Hope this helps also a useful link http://notes.ericjiang.com/posts/333

Or use the event.charCode which will return the ASCII code.



来源:https://stackoverflow.com/questions/4555006/ipad-javascript-character-codes-and-shiftkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!