关于keydown获取的按键ACSII值多个值,如何只保留最新那一个值?一下程序只弹出一种框
比如弹出38,就只能一直弹出38
定时器不能清掉
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-3.3.1.min.js">
</script>
<script type="text/javascript">
$(function(){
$(document).keydown(function(even){
setInterval(function(){
switch(even.keyCode){
case 37:
<span>alert</span>("37");
break;
case 38:
<span>alert</span>("38");
break;
case 39:
<span>alert</span>("39");
break;
case 40:
<span>alert</span>("40");
break;
default:
<span>alert</span>("00");
}
},800);
});
});
</script>
</head>
<body>
</body>
</html>
$(function() {
var lastKey;
$(document).keydown(function(e) {
switch(e.keyCode) {
case 37:
lastKey = e.keyCode;
break;
case 38:
lastKey = e.keyCode;
break;
//...................
}
alert(lastKey);
})
})