Blogger Information
Blog 250
fans 3
comment 0
visits 321898
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS鼠标对象
梁凯达的博客
Original
1045 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<button id="btn1">单击</button>
	<button id="btn2">双击</button>
</body>
<script>
var btn1 = document.getElementById('btn1');
var btn2 = document.getElementById('btn2');

btn1.onclick=function(){
	alert('单击事件')
}

btn2.ondblclick=function(){
	alert('双击事件')
}
</script>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<button id="btn">点妓</button>	
</body>
<script>
var  btn = document.getElementById('btn');

	//鼠标按下事件
	btn.onmousedown = function(){
		console.log('按下了鼠标');
	}
	//鼠标弹起事件
	btn.onmouseup = function(){
		console.log('鼠标弹起事件');
	}
	//鼠标单击事件
	btn.onclick=function(){
		console.log('点妓了一次');
	}
	//鼠标移动事件
	document.onmousemove=function(){
		//解决兼容性问题
		var e  = e ||event;
		document.title="X:"+e.clientX+"Y:"+e.clientY;
	}
</script>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post