脚本宝典收集整理的这篇文章主要介绍了jquery事件1:从hover说起,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
问题
今天碰到一个奇怪的问题,因为各种原因,要用到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/@H_304_12@点击预览
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.
参考
以上是脚本宝典为你收集整理的jquery事件1:从hover说起全部内容,希望文章能够帮你解决jquery事件1:从hover说起所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。