determine which key is pressed

后端 未结 4 766
南方客
南方客 2021-01-29 14:42

How to determine which key is pressed in javascript?

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 14:53

    In jQuery:

    jQuery(window).live('keydown', function(e) { 
      var keyCode = e.keyCode || e.which; 
    
      //do stuff with keycode
      } 
    });
    

    Normal:

    document.onkeyup = KeyCheck;       
    
    function KeyCheck(){
    
       var KeyID = event.keyCode;
       //do stuff
    }
    

提交回复
热议问题