onKeyPress event not working in Firefox

后端 未结 4 1812
闹比i
闹比i 2020-12-01 18:58

I have the following javascript code...Here I am using onKeyPress=\"someFunction( )\" in the body tag to get the keyCode of the key that is pressed.

4条回答
  •  佛祖请我去吃肉
    2020-12-01 19:54

    When problems like this show up, I start to use any kind of a JavaScript framework. Those frameworks are build to avoid problems with different browsers.

    To catch all different keypress() apis, like the link from Emmett shows, can be very difficult.

    Example:

    In HTML head:

    
    

    In the JS tag:

    $(document).keydown(function(event) {
     alert('You pressed '+event.keyCode);
     event.preventDefault();
    });
    

提交回复
热议问题