参考资料:https://www.cnblogs.com/rookieCat/p/4612312.html
;
(function ($, window, document, undefined) {
//私有 默认变量
var myPluginName = "imageUpload",
defaults = {
otherName: "value"
};
//私有 构造插件的函数
var ctorPlugin = function (element, options) {
this.element = element;
//利用jQuery 的extend 方法合并对象
this._default = defaults;
this.name = myPluginName;
this.init();
}
//原型链上添加方法
ctorPlugin.prototype.init = function () {
//执行一些初始化的逻辑,然后就可以访问DOM,进行一些业务处理
alert("haha");
};
//将插件包装起来,利用模块模式,防止多次实例出现
$.fn[myPluginName] = function (options) {
return this.each(function () {
var myPluginNameStr = "plugin_"
myPluginName;
if (!$.data(this, myPluginNameStr)) {
$.data(this, myPluginNameStr, new ctorPlugin(this, options));
}
});
};
})(jQuery, window, document);
// 使用插件
$(document).imageUpload({
});
网友评论