js中键盘按下事件,获取键值,在页面互动中操作键盘
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
<head>
<body>
<script type="text/javascript">
//页面中的任何位置,按下键盘,就可以获取按键的值
document.onkeydown=function(e){
console.log(e.keyCode);//事件参数对象e
}
</script>
</body>
</html>
其中的keyCode表示键值,在代码中需要操作哪些键时,可以用这些数字给需要的对象注册操作事件。