event.keycode not returning correct values in firefox

后端 未结 5 801
予麋鹿
予麋鹿 2020-12-31 00:24

I am trying the following code for triggering a js method when space-bar is pressed within an input box.

   

  $(\'#j1         


        
5条回答
  •  余生分开走
    2020-12-31 01:06

    The problem is not all browsers have the same implementations on keypresses. The solution would be to check all possible places where the key was registered. In this case: event.keycode and event.which

    See this post for more info

    jQuery Event Keypress: Which key was pressed?

    EDIT

    Finally dug up my old functions, this is the actual code that I use:

    evt = (evt) ? evt : event;
    var charCode = evt.which || evt.charCode || evt.keyCode || 0;
    

提交回复
热议问题