首页 > Web开发 > 详细

jquery mouseover与mouseenter,mouserout与mouseleave的区别

时间:2014-06-03 11:39:19      阅读:537      评论:0      收藏:0      [点我收藏+]

mouseover与mouseenter
不论鼠标指针穿过被选元素或其子元素,都会触发mouseover事件
只有在鼠标指针穿过被选元素时,才会触发mouseenter事件

bubuko.com,布布扣
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-1.6.4.min.js"></script>
<script type="text/javascript">
x=0;
y=0;
$(document).ready(function(){
  $("div.over").mouseover(function(){
    $(".over span").text(x+=1);
  });
  $("div.enter").mouseenter(function(){
    $(".enter span").text(y+=1);
  });
});
</script>
</head>
<body>
<p>不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件。</p>
<p>只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件。</p>
<div class="over" style="background-color:lightgray;padding:20px;width:40%;float:left">
<h2 style="background-color:white;">被触发的 Mouseover 事件:<span></span></h2>
</div>
<div class="enter" style="background-color:lightgray;padding:20px;width:40%;float:right">
<h2 style="background-color:white;">被触发的 Mouseenter 事件:<span></span></h2>
</div>
</body>
</html>
View Code

 

mouseout与mouseleave
不论鼠标指针离开被选元素还是任何子元素,都会触发mouseout事件
只有在鼠标指针离开被选元素时,才会触发mouseleave事件。

bubuko.com,布布扣
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-1.6.4.min.js"></script>
<script type="text/javascript">
x=0;
y=0;
$(document).ready(function(){
  $("div.over").mouseleave(function(){
    $(".over span").text(x+=1);
  });
  $("div.enter").mouseout(function(){
    $(".enter span").text(y+=1);
  });
});
</script>
</head>
<body>
<p>不论鼠标指针离开被选元素或任何子元素,都会触发 mouseout 事件。</p>
<p>只有在鼠标指针离开被选元素时,才会触发 mouseleave 事件。</p>
<div class="over" style="background-color:lightgray;padding:20px;width:40%;float:left">
<h2 style="background-color:white;">被触发的 Mouseover 事件:<span></span></h2>
</div>
<div class="enter" style="background-color:lightgray;padding:20px;width:40%;float:right">
<h2 style="background-color:white;">被触发的 Mouseenter 事件:<span></span></h2>
</div>
</body>
</html>
View Code

 

jquery mouseover与mouseenter,mouserout与mouseleave的区别,布布扣,bubuko.com

jquery mouseover与mouseenter,mouserout与mouseleave的区别

原文:http://www.cnblogs.com/ron123/p/3759994.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!