2010-06-14 96 views

回答

0

您可以處理document上的​​和keyup事件併爲每個鍵設置一個標誌。

其中採用的關鍵事件的函數
2

function(e){ 
    var key = String.fromCharCode(e.keyCode); 
} 
2

在jQuery中:

jQuery(window).live('keydown', function(e) { 
    var keyCode = e.keyCode || e.which; 

    //do stuff with keycode 
    } 
}); 

正常:

document.onkeyup = KeyCheck;  

function KeyCheck(){ 

    var KeyID = event.keyCode; 
    //do stuff 
} 
0

在JavaScript:

function myKeyPress(e){ 
    var keynum; 
    if(window.event){ // IE 
     keynum = e.keyCode; 
    }else 
    if(e.which){ // Netscape/Firefox/Opera 
     keynum = e.which; 
    } 
    alert(String.fromCharCode(keynum)); 
    alert(keynum); 
    if (keynum == 13) { 
     alert("You Pressed Enter Key"); 
    } 
} 

In HTML:

<textarea name="box" id="box" onkeypress="return myKeyPress(event)"></textarea>