2012-02-06 44 views
0

我試圖通過this訪問插件,以便引用稍後在鏈中添加的方法。是指插件內的插件對象

$.fn.test = function(){ 

    console.log(this); 
} 

this指的是我已經使用調用插件的元素,而不是插件本身。

我該如何訪問插件,並因此連接到它的任何方法?

回答

0

如果您需要jQuery對象,請使用$(this)

你也可以嘗試這個插件添加到jQuery。

(function($){ 

    $.extend($.fn, { 
     test: function(){ 
      //Plugin code here 
      //here this will point to jQuery object 
     } 
    }; 
})(jQuery);