jQuery: how to filter out non-character keys on keypress event?

前端 未结 5 1006
不知归路
不知归路 2020-12-08 02:39

I tried searching but unsure of what terms to look for.

I\'m using jQuery and would like to use the keypress event in a textbox, but prevent all non-printable charac

5条回答
  •  一整个雨季
    2020-12-08 03:26

    
    

    Seems to work just fine with jQuery 1.4.2, FF, IE, Chrome.

    To delve into the mess that is JS keyboard event handling, see: JavaScript Madness: Keyboard Events


    Updated to filter ctrl, meta & alt key combinations as per Daniel's comment.

提交回复
热议问题