javascript怎么判断键盘一直在按下,
2个回答
展开全部
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv='content-Type' content='text/html;charset=utf-8'>
</HEAD>
<script>
var flag=false;
function up(event){
var event=event||window.event;
var obj=document.getElementById('red');
if(event.keyCode==65){
obj.innerHTML='你已经松开了a键';
}
}
function down(event){
var event=event||window.event;
var obj=document.getElementById('red');
if(event.keyCode==65){
obj.innerHTML='你就这么一直按着a键';
}
}
</script>
<BODY onload='window.document.onkeyup=up;window.document.onkeydown=down'>
<div id='red' style='height:200px;width:200px;border:1px solid red;'></div>
</BODY>
</HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv='content-Type' content='text/html;charset=utf-8'>
</HEAD>
<script>
var flag=false;
function up(event){
var event=event||window.event;
var obj=document.getElementById('red');
if(event.keyCode==65){
obj.innerHTML='你已经松开了a键';
}
}
function down(event){
var event=event||window.event;
var obj=document.getElementById('red');
if(event.keyCode==65){
obj.innerHTML='你就这么一直按着a键';
}
}
</script>
<BODY onload='window.document.onkeyup=up;window.document.onkeydown=down'>
<div id='red' style='height:200px;width:200px;border:1px solid red;'></div>
</BODY>
</HTML>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询