<!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>