?
<SCRIPT>
function fnTrapKD(){
?? if(oTrap.checked){
????? oOutput.innerText+="[trap = " + event.keyCode + "]";
????? event.returnValue=false;
?? }
?? else{
????? oOutput.innerText+=String.fromCharCode(event.keyCode);
?? }
}
function test()
{
?if (event.keyCode==13)
?{
??alert("press enter");
?}
?
}
</SCRIPT>
<INPUT TYPE="checkbox" ID="oTrap" checked>顯示按鍵的keyCode<br />
在該輸入框按鍵:<INPUT ID="oExample" TYPE="text" onkeydown="fnTrapKD()"><br />
<TEXTAREA ID="oOutput" ROWS="10" COLS="50">
</TEXTAREA>
<br />
<INPUT ID="oExample1" TYPE="text" onkeydown="test()">
<SCRIPT>
document.write( String.fromCharCode( 81,49 ) + "<br>" );
</SCRIPT>
使用event,keyCode來捕獲編碼,再用String的fromCharCode方法轉換成字母(大寫)
The
fromCharCode(
num1,num2,…,
numN) method is a static String method that creates a string containing one or more characters whose Unicode values are passed as parameters.