2012-02-06 72 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);