jquery事件1:从hover提及

问题

今天碰到一个奇怪的问题,由于各类缘由,要用到jquery1.8.3和jquery1.9.1这两个版本,发现两个版本对hover的处理不同,1.8.3能够bind(还有delegate,on) hover事件,像click事件同样,但1.9.1不行,只能是$(XX).hover(function(){})jquery

Demo1:$(XX).hover(function(){})app

http://jsfiddle.net/1wra9kgt/ide

Demo2: 1.8.3的delegate$(xx).delegate()方式ui

http://jsfiddle.net/1wra9kgt/3/this

Demo3: 1.9.1的delegate$(xx).delegate()方式.net

http://jsfiddle.net/1wra9kgt/2/code

抛出2个问题:
一、Demo1 实现机制
二、Demo2与Demo3的实现区别事件

第1个问题,看源码,两个都是同样的get

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升级指南

相关文章
相关标签/搜索