javascript实现捕捉键盘上按下的键


小小的demo,用js捕捉键盘盘上按下了那个键,然后展示出对应的code值

<!DOCTYPE html>
<html>
<head>
<script>
function showKeyCode(event)
{
document.getElementById("result").value= event.keyCode;
}
 
</script>
</head>
 
<body onkeyup="showKeyCode(event)">
<p>按下键盘上的键,文本框中会显示对应的code</p>
<input type="text" id="result" value="1" />
</body>
 
</html>

以上所述就是本文的全部内容了,希望大家能够喜欢。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3