What is the keyCode for “$”?

前端 未结 5 1846
萌比男神i
萌比男神i 2021-01-18 06:07

I am trying to disable all other characters from being entered in text input.

Since to get the $ you have to press the shift-key and the

5条回答
  •  清歌不尽
    2021-01-18 06:52

    Key codes relate only to keys. $ is a character, achieved through two keys, Shift and 4. There is no key code explicitly for $ when using onkeydown

    Edit: It was pointed out by Edward that onkeypress uses key combinations, and does have keycode's for combinations. Learn something new every day :)

    Here's some code, edited from the onkeydown example provided by the MDN, to detect keypress keycodes.

    Here's the fiddle updated to be Firefox-friendly, using help from this S.O. post. The JQuery solution works too, if you swing that way.

提交回复
热议问题