JavaScript 鍵盤按下事件
阿新 • • 發佈:2018-11-27
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script language="JavaScript">
function keydown(){
var imgs = document.images[0];
if(event.keyCode==38){
imgs.style.pixelTop-=20;
}else if(event.keyCode==40){
imgs.style.pixelTop+=20;
}else if(event.keyCode==37){
imgs.style.pixelLeft-=20;
}else if(event.keyCode==39){
imgs.style.pixelLeft+=20;
}
}
window.onkeydown=keydown;
</script>
</head>
<body>
<img src="image/s.jpg" style="width: 150px;height: 300px;position: absolute" id="imgs">
</body>
</html>