onKeyPress event not working in Firefox

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

    Pass event object as an parameter and your code will work in IE as well as firefox. The code example is as follows :

    
    
    function keypress(event) {
      alert(event.keyCode);
      var key=event.keyCode;
      if(key==112 || key==80)
          printDiv();
      else if(key==101 || key==69)
          window.location="http://google.com";
      else if(key==114 || key==82)
          window.reset();  
    }
    

提交回复
热议问题