How do I use the Keydown event to get the correct character in multiple languages/keyboard layouts?

前端 未结 1 974
余生分开走
余生分开走 2020-12-10 08:02

I use keydown event in jquery, but the problem it\'s stateless for input language. It\'s can\'t determine the input is in English language or in Hebrew or Arabic...? it ret

1条回答
  •  情深已故
    2020-12-10 08:30

    To determine the actual character, you should use the keypress event instead of keydown. While keydown provides you with a key code, keypress indicates the character which was entered by the user.

    Another difference is that when the user presses and holds a key, a keydown event is triggered only once, but separate keypress events are triggered for each inserted character.

    Here's an example of using the keypress event:

    
    

    0 讨论(0)
提交回复
热议问题