【发布时间】:2012-02-06 17:01:38
【问题描述】:
我正在尝试通过this 访问插件,以便引用稍后添加到链中的方法。
$.fn.test = function(){
console.log(this);
}
但this 指的是我用来调用插件的元素,而不是插件本身。
如何访问插件,以及附加的任何方法?
【问题讨论】:
标签: javascript jquery oop plugins prototypal-inheritance
我正在尝试通过this 访问插件,以便引用稍后添加到链中的方法。
$.fn.test = function(){
console.log(this);
}
但this 指的是我用来调用插件的元素,而不是插件本身。
如何访问插件,以及附加的任何方法?
【问题讨论】:
标签: javascript jquery oop plugins prototypal-inheritance
如果需要 jQuery 对象,请使用 $(this)。
你也可以试试这个给jQuery添加插件。
(function($){
$.extend($.fn, {
test: function(){
//Plugin code here
//here this will point to jQuery object
}
};
})(jQuery);
【讨论】: