【发布时间】:2015-05-28 11:48:53
【问题描述】:
我有一个关于 jQuery 的 mouseover 和 mouseout 方法的问题。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
#land {
background: #FFCC33;
width: 200px;
height: 200px;
}
#water {
background: #33CCCC;
width: 150px;
height: 150px;
}
#island {
background: #33FF33;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="land">
<div id="water">
<div id="island"></div>
</div>
</div>
</body>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$("#land").on({
"mouseover" : function() {
console.log("land - mouse over");
},
"mouseout" : function() {
console.log("land - mouse out");
}
});
});
</script>
</html>
当鼠标移动“陆地”->“水”时,鼠标悬停事件发生。 当 'water' -> 'island' 鼠标移出并发生鼠标悬停事件时。
为什么会发生鼠标悬停事件???
【问题讨论】:
-
岛屿元素包含在水元素中,水元素包含在陆地元素中,所以实际上如果你将鼠标悬停在岛屿上,你就是在陆地、水和岛屿上进行鼠标悬停