jquery事件1:从hover说起
2015-01-04 15:02
381 查看
问题
今天碰到一个奇怪的问题,因为各种原因,要用到jquery1.8.3和jquery1.9.1这两个版本,发现两个版本对hover的处理不一样,1.8.3可以bind(还有delegate,on) hover事件,像click事件一样,但1.9.1不行,只能是$(XX).hover(function(){})Demo1:
$(XX).hover(function(){})
http://jsfiddle.net/1wra9kgt/
Demo2: 1.8.3的delegate
$(xx).delegate()方式
http://jsfiddle.net/1wra9kgt/3/
Demo3: 1.9.1的delegate
$(xx).delegate()方式
http://jsfiddle.net/1wra9kgt/2/
抛出2个问题:
1、Demo1 实现机制
2、Demo2与Demo3的实现区别
第1个问题,看源码,两个都是一样的
hover: function( fnOver, fnOut ) { return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); }
第2个问题,1.9的版本对事件做了很大的变化,去掉了toggle,live和die事件,对hover也有这么一段解释
As of 1.9, the event name string "hover" is no longer supported as a
synonym for "mouseenter mouseleave". This allows applications to
attach and trigger a custom "hover" event. Changing existing code is a
simple find/replace, and the "hover" pseudo-event is also supported in
the jQuery Migrate plugin to simplify migration.
参考
jquery1.9升级指南相关文章推荐
- jQuery 的 live() 方法对 hover 事件的处理
- 为hover事件加上延迟jquery.hoverIntent
- jQuery 的 live() 方法对 hover 事件的处理
- jQuery hover事件
- jQuery hover(over, out)事件函数
- jQuery 中的合成事件 hover() & toggle()
- jQuery 鼠标经过(hover)事件的延时处理示例
- jQuery 的 live() 方法对 hover 事件的处理
- jQuery hover 事件制作jquery菜单
- jQuery – 鼠标经过(hover)事件的延时处理
- jQuery – 鼠标经过(hover)事件的延时处理
- 【js与jquery】www.zhen.com首页<li>标签的hover事件
- jquery hover()事件函数
- jQuery 的 live() 方法对 hover 事件的处理
- $().hover();和$().toggle();中的jquery事件切换
- 我是如何去了解jquery的(四),切换事件hover&toggle
- jQuery 的 live() 方法对 hover 事件的处理
- JQuery入门――事件切换之hover()方法应用介绍
- jQuery 的 live() 方法对 hover 事件的处理
- jQuery 鼠标经过(hover)事件的延时处理示例