JavaScript 获取keycode问题,问题如下
functionkeyUp(e){vare=e||event;varcurrKey=e.keyCode;varkeyName=String.fromCharCode(cu...
function keyUp(e) {
var e=e || event;
var currKey=e.keyCode;
var keyName = String.fromCharCode(currKey);
if(currKey == 96) keyName = 0;
if(currKey == 97) keyName = 1;
if(currKey == 98) keyName = 2;
if(currKey == 99) keyName = 3;
if(currKey == 100) keyName = 4;
if(currKey == 101) keyName = 5;
if(currKey == 102) keyName = 6;
if(currKey == 103) keyName = 7;
if(currKey == 104) keyName = 8;
if(currKey == 105) keyName = 9;
if(currKey == 106) keyName = "*";
document.getElementById("key").innerHTML = "按键码: " + currKey+ " 字符: " + keyName;
}
document.onkeyup = keyUp;//当键盘松开时
<div id="key" style="color:red;"></div>
--------------------------------------
1.var e=e || event;是什么意思
2. var currKey=e.keyCode;是什么意思 展开
var e=e || event;
var currKey=e.keyCode;
var keyName = String.fromCharCode(currKey);
if(currKey == 96) keyName = 0;
if(currKey == 97) keyName = 1;
if(currKey == 98) keyName = 2;
if(currKey == 99) keyName = 3;
if(currKey == 100) keyName = 4;
if(currKey == 101) keyName = 5;
if(currKey == 102) keyName = 6;
if(currKey == 103) keyName = 7;
if(currKey == 104) keyName = 8;
if(currKey == 105) keyName = 9;
if(currKey == 106) keyName = "*";
document.getElementById("key").innerHTML = "按键码: " + currKey+ " 字符: " + keyName;
}
document.onkeyup = keyUp;//当键盘松开时
<div id="key" style="color:red;"></div>
--------------------------------------
1.var e=e || event;是什么意思
2. var currKey=e.keyCode;是什么意思 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询