jQuery Event Keypress: Which key was pressed? A-Z, & @

后端 未结 3 807
小蘑菇
小蘑菇 2021-01-06 00:41

on a keydown I get the following from jQuery:

jQuery.Event
altKey: false
attrChange: undefined
attrName: undefined
bubbles: true
button: undefined
cancelable         


        
3条回答
  •  孤城傲影
    2021-01-06 01:08

    Here is the fiddle that matches your exact requirement
    http://jsfiddle.net/cSc7r/

    You may have to use

      String.fromCharCode(key_event.which);
    

    or

      String.fromCharCode(event.keyCode); // For IE
    

    However if you want to run any event on key press here is a nice plugin to make it very easily. Please check this fiddle http://jsfiddle.net/zUc4Z/.

提交回复
热议问题