posts - 501,comments - 0,views - 23802

视频

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>19_事件切换</title>
</head>
<style type="text/css">
	* {
		margin: 0px;
	}
	.div1 {
		position: absolute;
		width: 200px;
		height: 200px;
		top: 50px;
		left: 10px;
		background: olive;
	}
	.div2 {
		position: absolute;
		width: 100px;
		height: 100px;
		top: 50px;
		background: red;
	}
	.div3 {
		position: absolute;
		width: 200px;
		height: 200px;
		top: 50px;
		left: 230px;
		background: olive;
	}
	.div4 {
		position: absolute;
		width: 100px;
		height: 100px;
		top: 50px;
		background: yellow;
	}

	.divText{
		position: absolute;
		top: 330px;
		left: 10px;
	}

</style>
<body>

<div class="divText">
	区分鼠标的事件
</div>

<div class="div1">
	div1.....
	<div class="div2">div2....</div>
</div>

<div class="div3">
	div3.....
	<div class="div4">div4....</div>
</div>
<!--
区别mouseover与mouseenter?
	* mouseover: 在移入子元素时也会触发, 对应mouseout
	* mouseenter: 只在移入当前元素时才触发, 对应mouseleave
								hover()使用的就是mouseenter()和mouseleave()

区别on('eventName',fun)和eventName(fun)
	*on('eventName',fun):通用,但编码麻烦
	*eventName(fun):有的事件没有对应方法,但编码简单
-->
<script src="js/jquery-1.10.1.js" type="text/javascript"></script>
<script type="text/javascript">

	$('.div1').mouseover(function () {
		console.log('移入div1或其子元素')
	}).mouseout(function () {
		console.log('移出div1或其子元素')
	})

	$('.div3').mouseenter(function () {
		console.log('移入div3元素')
	}).mouseleave(function () {
		console.log('移出div3元素')
	})

	$('.div3').hover(function () {
		console.log('移入div33元素')
		this.style.background = 'red'
	}, function () {
		console.log('移出div33元素')
		this.style.background = 'blue'
	})
</script>
</body>
</html>

posted on   垂序葎草  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示