今天碰到一個奇怪的問題,由於各類緣由,要用到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.