鼠标穿透事件

<body>
		<div style="height: 50px;border: #000000 2px solid;">
			<a href="">fvhdfiohvg</a>
		</div>
		<script type="text/javascript">
			let a=document.getElementsByTagName('a')[0];
			let d=document.getElementsByTagName('div')[0];
			a.onclick=function(e){//接受一个参数
				// 取消默认事件:即跳转
				e.preventDefault();
				// 不点击外部:即窗口和div
				e.stopPropagation();
				console.log(2);
			}
			d.onclick=function(){
				console.log('hfohduf')
				// 没有取消,会输出3
			}
			window.onclick=function(){
				console.log(3)
			}
			
		</script>
	</body>

猜你喜欢

转载自blog.csdn.net/baidu_40450846/article/details/88531529