<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<!-- mouseover、mouseenter的区别:div里套div。见备注。和事件冒泡有关系。
不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件
只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件(穿过子元素不会触发)-->
<style type="text/css">
div{margin:auto;}
#parent{width:300px;height:300px;margin-top:100px;background-color:Red;}
#child{width:100px;height:100px;background-color:gold;position:relative;top:100px;}
</style>
<script src="../js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#parent").mouseenter(function () {
alert('parent div enter');
});
$("#parent").mouseover(function () {
alert('parent div over');
});
$("#child").mouseenter(function () {
alert('child div enter');
});
$("#child").mouseover(function () {
alert('child div over');
});
});
</script>
</head>
<body>
<div id="parent">
<div id="child">
</div>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<!-- mouseover、mouseenter的区别:div里套div。见备注。和事件冒泡有关系。
不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件
只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件(穿过子元素不会触发)-->
<style type="text/css">
div{margin:auto;}
#parent{width:300px;height:300px;margin-top:100px;background-color:Red;}
#child{width:100px;height:100px;background-color:gold;position:relative;top:100px;}
</style>
<script src="../js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#parent").mouseenter(function () {
alert('parent div enter');
});
$("#parent").mouseover(function () {
alert('parent div over');
});
$("#child").mouseenter(function () {
alert('child div enter');
});
$("#child").mouseover(function () {
alert('child div over');
});
});
</script>
</head>
<body>
<div id="parent">
<div id="child">
</div>
</div>
</body>
</html>
本文通过HTML、CSS和JavaScript代码实例,详细解释了HTML元素上的mouseover和mouseenter事件的区别,包括它们如何响应鼠标操作,以及在父元素与子元素上的行为差异。
2462

被折叠的 条评论
为什么被折叠?



