您的位置:首页 > Web前端 > JQuery

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升级指南
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: