onKeyPress event not working in Firefox

后端 未结 4 1808
闹比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:47

    Browsers have different ways of handling keyboard events. Have a look at http://unixpapa.com/js/key.html for more info.

    For example, these changes to your code will get it working in Firefox:

    
    

    and

    function keypress(e) {
        alert(window.event ? event.keyCode : e.which);
        // other stuff
    }
    

提交回复
热议问题