<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>KeyDown</title>
</head>
<body>
<div>
<input type="text" id="inpcode" />
<input type="text" id="inpval" />
</div>
<script type="text/javascript">
window.document.onkeydown = fun;
function fun(evt) {
evt = (evt) ? evt : window.event
evt.preventDefault();
if (evt.keyCode) {
document.getElementById('inpcode').value = evt.keyCode
document.getElementById('inpval').value = String.fromCharCode(evt.keyCode)
}
}
</script>
</body>
</html>
js KeyDown 当键盘按下时 获取所按键的Code
于 2023-11-24 13:20:47 首次发布