键盘事件
1.onkeydown:按钮按下时触发
2.onkeyup:按钮弹起时触发
用的比较多的是onkeydown事件,我们可以捕获到键盘按键,常常被用来点击enter键时去执行一系列操作,来代替点击确定或登录按钮,下面展示enter键来触发事件
<html>
<head>
<title></title>
</head>
<script>
window.onload=function(){
document.onkeydown=function(ev){
var event=ev ||event
if(event.keyCode==13){
alert("按了enter键")
}
}
}
</script>
<body>
</body>
</html>
