2011-03-28 40 views
0

是否有可能在Jquery擁有它,當我解綁時,在.myBox上,它做了什麼?我想將它添加到我製作的第一個插件中,不知道如何?jquery:當'懸停'在'.myBox'上解除綁定時做些什麼?

當解綁定懸停在特定元素上時,我總是需要做某些特定的事情,比如css('cursor','default')和其他一些事情。有沒有辦法在事情沒有約束時觸發東西,而不必在宣佈解除綁定時做這些事情?

回答

2

這樣做將是擴展的unbind函數本身的唯一方法:

(function ($) { 

    var unbind = jQuery.fn.unbind; 

    jQuery.fn.unbind = function(type, func) { 
     var matchedElements = this.filter('#matchedElement1,#matchedElement2'); 
     if (matchedElements.length && typeof type == "string" && type == "mouseover") { 
      // Blah Blah, whatever you wanted to do (do it to matchedElements rather than this). 
     } 

     return unbind.apply(this, arguments); // Call the actual unbind handler. 
    }; 

    /* The rest of your plugin */ 

}(jQuery)); 
+0

** [DEMO](http://jsfiddle.net/W6Sw5/)** – qwertymk 2011-03-28 11:58:36