首页> 基础笔记 >JS/JQ基础学习 >事件 事件

JavaScript-组合按键事件

作者: 2023-03-22 浏览 295

简介JavaScript-组合按键事件

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>组合按键</title>
</head>
<body>
	<script type="text/javascript">
	//window绑定键盘按下事件
	window.onkeypress = function(e){
		console.log(e);
		//ctrl+q加血
		if(e.key == 'q' && e.ctrlKey == true){
			alert('正在加血呢.....');
		}
		
		//加蓝
		if(e.key == 'y' && e.altKey == true){
			alert('正在加蓝中....');
		}

		//放技能
		if(e.key == 'Q' && e.shiftKey == true){
			alert('正在放技能中...');
		}

		//放大招
		if(e.key == 'C' && e.shiftKey == true && e.ctrlKey == true && e.altKey == true){
			alert('正在放大招呢....');
		}


	}
	</script>
</body>
</html>
 

很赞哦! (0)

文章评论

    高端网站建设