我创建了一个插件,可以将选择器元素转换为模态弹出窗口。
例如:
$(".ModalPopup").ModalPopup();
但是,在某些情况下,该ModalPopup元素将不存在于 DOM 中。
在这种情况下,我想在插件中动态创建元素ModalPopup,因此只能调用:
$.ModalPopup();
是否有可能有一个使用和不使用选择器的 jQuery 插件?
如果是这样,我该怎么做?我目前有(简化):
;(function ($,window,document,undefined) {
    function ModalPopup(element, options){
        this.element = element;
        this.options = $.extend({}, defaults, options);
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }
    $.fn[pluginName] = function (options) { 
       new ModalPopup(this, options);  
    };
})(jQuery, window, document);