0

在 Jquery 中是否有可能拥有它,当我解除悬停时.myBox,它会做些什么?我想将它添加到我正在制作的第一个插件中,不知道如何?

当取消绑定悬停在特定元素上时,我总是希望完成一些特定的事情,比如 css('cursor', 'default') 和其他一些事情。有没有办法在某些东西未绑定时触发某些东西,而在声明解除绑定时不必做这些事情?

4

1 回答 1

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));
于 2011-03-28T11:15:33.933 回答