event.keycode not returning correct values in firefox

后端 未结 5 622
予麋鹿
予麋鹿 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:12

    if you're getting a 0 no matter which key you press, try using charCode instead of keyCode

    This happens because you are calling the KeyboardEvent object which uses which and charCode as opposed to the Event object which uses keyCode for returning keyboard Unicode values. For more information, refer to MDN web docs for more information regarding the KeyboardEvent: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent

提交回复
热议问题