【问题标题】:refer to the plugin object within the plugin引用插件内的插件对象
【发布时间】:2012-02-06 17:01:38
【问题描述】:

我正在尝试通过this 访问插件,以便引用稍后添加到链中的方法。

$.fn.test = function(){

    console.log(this);
}

this 指的是我用来调用插件的元素,而不是插件本身。

如何访问插件,以及附加的任何方法?

【问题讨论】:

    标签: javascript jquery oop plugins prototypal-inheritance


    【解决方案1】:

    如果需要 jQuery 对象,请使用 $(this)

    你也可以试试这个给jQuery添加插件。

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

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 2019-09-10
      • 2012-06-14
      • 1970-01-01
      • 2018-03-28
      相关资源
      最近更新 更多