js判断鼠标点击的是哪个键

鼠标事件

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	
	<body>
		<div>
			<button onmousedown="whichButton(event)">点击</button>
		</div>
	</body>
	<script type="text/javascript">
		
		function whichButton(event)
		{
			var btnNum = event.button;
			if (btnNum==2)
			{
				alert("您点击了鼠标右键!")
			}
			else if(btnNum==0)
			{
				alert("您点击了鼠标左键!")
			}
			else if(btnNum==1)
			{
				alert("您点击了鼠标中键!");
			}
			else
			{
				alert("您点击了" + btnNum+ "号键,我不能确定它的名称。");
			}
		}
	
	</script>
</html>
posted @ 2019-12-12 08:59  千金一发  阅读(641)  评论(0编辑  收藏  举报