<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> #div1{height: 100px; width: 100px; position: absolute; background: gray;} </style> <script>window.onload=function() { var odiv=document.getElementById("div1"); var timer=null; document.onkeyup=function(){ clearInterval(timer); } document.onkeydown=function(ev){ var oEven=ev||event timer=setInterval(function(){ if(oEven.keyCode==37){ odiv.style.left=odiv.offsetLeft-10+"px"; } else if (oEven.keyCode==39){ odiv.style.left=odiv.offsetLeft+10+"px"; }},100) }} </script></head><body><div id="div1"></div></body></html>
添加回答
举报
0/150
提交
取消