jQuery关于mouseover和mouseenter的区别
2016-05-12 18:09
579 查看
原生的mouseenter是dom3级的事件,对于jQuery等一些框架已经实现了这个事件。但是它到底跟mouseover有什么区别?
jQuery在实现这两个事件的时候,mouseover支持事件冒泡,在父级注册事件,子元素也会触发此事件。而mouseenter只有鼠标划到注册事件的元素才会触发。
看个例子:
jQuery在实现这两个事件的时候,mouseover支持事件冒泡,在父级注册事件,子元素也会触发此事件。而mouseenter只有鼠标划到注册事件的元素才会触发。
看个例子:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.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> <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>
相关文章推荐
- jquery修改display属性
- 第26篇 jQuery 快速学习下
- jQuery 获取 checkbox、select、radio值
- ECSHOP用Jquery的getJSON实现两网站之间跨域读取
- jquery 获取属性的值
- Ecshop与Jquery冲突的解决方案2
- jquery tmpl $被jsp jstl占用
- ecshop jquery冲突解决方法
- jQuery的XX如何实现?——4.类型检查
- 使用jQuery制作遮罩层弹出效果的极简实例分享
- 项目中使用的jqGrid
- 使用jQuery实现Web页面换肤功能的要点解析
- jQuery中$.each()函数的用法引申实例
- jquery操作select大全详解
- jQuery基础——事件篇
- jquery实现select二级联动
- jQuery触发事件
- jQuery选择器
- jQuery中find和filter的区别
- 使用jQuery.form.js/springmvc框架实现文件上传功能