亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 250
粉絲 3
評(píng)論 0
訪問(wèn)量 381683
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
JS--鍵盤(pán)事件
梁凱達(dá)的博客
原創(chuàng)
1273人瀏覽過(guò)

 

實(shí)例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	
</body>
<script>

document.onkeydown = function(e){
	var e =  e || event;
	//alert(e.keyCode);
	//alert(e.shiftKey);
	if(e.shiftKey){
		if (e.keyCode == 65) {
			alert('我按了一下A鍵')
		}
	}
	console.log('我按下了鍵盤(pán)')
}
document.onkeyup = function(){
	console.log('我松開(kāi)了鍵盤(pán)')
}
document.onkeypress = function(){
	console.log('按了一次鍵盤(pán)')
}
</script>
</html>

實(shí)例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		*{margin:0px;padding:0px;}
		#box{width:100px;height:100px;position:absolute;/*background:pink;*/}
		#parent{width:400px;height:400px;border:1px solid red;background-image:url(./bg.jpg);}
	</style>
</head>
<body>
<div id="parent">
	<div id="box" style="left:0px;top:0px;">
		<img src="./me.png" alt="">
	</div>
</div>
	
</body>
<script>
var  box = document.getElementById('box');

//上鍵 38
//下鍵 40
//左鍵 37
//右鍵 39
document.onkeydown = function(e){
	var e  = e || event;
	//alert(e.keyCode);
	switch(e.keyCode){
		case 37:
			if((parseInt(box.style.left)-10)>0){
			//alert('按了左鍵')
				box.style.left = parseInt(box.style.left)-10+'px';
			}else{
				box.style.left = '0px';
			}
			break;
		case 38:
			if((parseInt(box.style.top)-10)>0){
			//alert('按了上鍵')
				box.style.top = parseInt(box.style.top)-10+"px";
			}else{
				box.style.top="0px";
			}
			break;
		case 39:
			//alert('按了右鍵')
			if(parseInt(box.style.left)< 300){
				box.style.left = parseInt(box.style.left) + 10 + 'px';
			}else{
				box.style.left= 300+'px';
			}
			break;
		case 40:
			//alert('按了下鍵')
			if(parseInt(box.style.top) < 300){
				box.style.top = parseInt(box.style.top) + 10 +'px';
			}else{
				box.style.top='300px';
			}
			break;
	}
}
</script>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

 

本博文版權(quán)歸博主所有,轉(zhuǎn)載請(qǐng)注明地址!如有侵權(quán)、違法,請(qǐng)聯(lián)系admin@php.cn舉報(bào)處理!
全部評(píng)論 文明上網(wǎng)理性發(fā)言,請(qǐng)遵守新聞評(píng)論服務(wù)協(xié)議
0條評(píng)論
作者最新博文
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)