JavaScript keyboard event

<! DOCTYPE HTML> 
<HTML> 
    <head> 
        <Meta charset = "UTF-. 8"> 
        <title> </ title> 
        <Script type = "text / JavaScript"> 
            the window.onload = function () {
                 / * keyboard events 
                 * onkeydown button is pressed, the press has been continuously triggers 
                 * onkeyup 
                 * - usually bind keyboard events to get to be the focal point of the object or the Document 
                 * / 
                // 1. 
                document.onkeydown = function (event) {
                     // keyCode to for the key code, to determine whether that key is pressed 
                    // there altKey shiftKry altKey the like determines whether the pressed 
//                     Console.log ( "press button");
                    IF (event.keyCode == 89 ) { 
                        the console.log ( "Y button pressed" ); 
                    } 
                    IF (event.altKey && event.keyCode == 89 ) { 
                        the console.log ( "Alt key while pressing the + Y a " ); 
                    } 
                } 
//                 document.onkeyup = function () { 
//                     the console.log (" key release "); 
//                 } 
                
                // 2. 
                var INPUT = document.getElementsByTagName (" INPUT ") [0 ] ; 
                the INPUT.onkeydown=function(){
                    //the console.log ( "input pressed"); 
                    // can not be used to limit the input of the input digital 
                    IF (event.keyCode> = 48 && event.keyCode <= 57 is) { // numbers 1-9 corresponding to 48-57 
                        / / cancel the default behavior of input of the input something not show 
                        return  to false ; 
                    } 
            } 
            }
            
            
         </ Script> 
    </ head> 
    <body> 
        <form Action = "" Method = "POST"> 
            
            <input type = "" value = " "/> 
        </ form> 
    </ body> 
</ HTML>

 

Guess you like

Origin www.cnblogs.com/wangdongwei/p/11298276.html