我是一个非常新的jQuery用户,希望扩展现有的jQuery插件,该插件可以完成我所需的75%的功能.我试着在这方面做功课.我已经判断了stackoverflow的以下问题:

我有read up个扩展方法.然而,所有这些家庭作业(job)让我感到困惑.我正在使用fullcalendar插件,需要修改一些行为以及添加新的事件挂钩.我是否被困在插件关闭本身中?我是不是漏掉了什么明显的东西?

Ideally we would be able to separate our code from the plugin code to allow for a possible upgrade. Any help would be greatly appreciated, especially pointers on where I'm missing some information or opinions on whether the solutions already presented in other Stack Overflow questions make sense. To me they contradict each other and I'm still left confused.

推荐答案

I just had the same problem trying to extend jquery UI plugins, and here is the solution I found (found it through jquery.ui.widget.js):


(function($) {
/**
 *  Namespace: the namespace the plugin is located under
 *  pluginName: the name of the plugin
 */
    var extensionMethods = {
        /*
         * retrieve the id of the element
         * this is some context within the existing plugin
         */
        showId: function(){
            return this.element[0].id;
        }
    };

    $.extend(true, $[ Namespace ][ pluginName ].prototype, extensionMethods);


})(jQuery);

希望这有帮助,如果你有任何问题,请询问.

Jquery相关问答推荐

ASP.NET Core 8 MVC:从jQuery发布控制器中的所有值为空

如何在for循环期间上传文件

如何使 Bootstrap 轮播滑块使用移动左/右滑动

为什么 jQuery 不使用 requestAnimationFrame?

jQuery / Ajax - $.ajax() 将参数传递给回调 - 使用好的模式?

在 Javascript 中,字典理解或 Object `map`

ajax调用后jQuery点击功能不起作用?

我可以限制 JavaScript 中数组的长度吗?

jquery-ui datepicker更改z-index

jQuery .load() 调用不会在加载的 HTML 文件中执行 JavaScript

jquery beforeunload 关闭(不离开)页面时?

使用 JQuery / JavaScript 调用/单击 mailto 链接

为什么使用 jQuery on() 而不是 click()

DataTables:无法读取未定义的属性长度

jQuery ajax (jsonp) 忽略超时并且不触发错误事件

是否可以在 beforeunload 弹出窗口中显示自定义消息?

将图像 url 转换为 Base64

如何重新加载/刷新 jQuery 数据表?

如何在文件 Select 上触发事件

将多个参数传递给 jQuery ajax 调用