【mouseenter mouseover】jquery中mouseenter和mouseleave事件示例

更新时间:2018-09-03    来源:jquery    手机版     字体:

【www.bbyears.com--jquery】

但是由于javascript的dom事件传播机制,不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件,不论鼠标指针离开被选元素还是任何子元素,都会触发 mouseout 事件。

所有jquery提供了mouseenter和mouseleave事件来终止事件传播,使事件只发生在选中的元素上。

只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件。

只有在鼠标指针离开被选元素时,才会触发 mouseleave 事件。

 代码如下





jQuery中的mouseenter和mouseleave事件

<script type="text/javascript" src="h/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#sel-down-w").mousemove(function(){
  $(".sns-setting-box").slideDown().mouseleave(function(){
   $(this).slideUp()
  })
 })
});
</script>



     设置
     
       
个人资料
隐私设置
动态过滤
邮件提醒
word">密码修改

     
   
  

兼容IE6的mouseenter和mouseleave事件

在IE6下,鼠标移上所指的内容,会闪来闪去,所以用jQuery里mouseenter和mouseleave,
额,这语法很怪异,我从来没见过这样的。
恩,收集起来,作为参考吧。

 代码如下

$(document).ready(function(){
$(".search-photo-img").mouseenter(function(){
$(this).css("background","url(module/search/templates/default/images/photo-img-onbg.gif)").mouseleave(function(){
$(this).css("background","");
});
});
});

本文来源:http://www.bbyears.com/wangyezhizuo/44062.html

猜你感兴趣