标签:
(function ($) { /** * 创建dom * @param $this * @returns {boolean} */ function createHtml($this) { _init($this); } /** * 初始化 * @private */ function _init($this) { } //public method var methods = { init: function (initOptions) { options = $.extend({}, $.fn.jqueryPluginName.defaults, initOptions); var $this = $(this); return this.each(function () { createHtml($this); }); }, destroy: function () { return this.each(function () { }); }, option: function (key, value) { if (arguments.length == 2) return this.each(function () { if (options[key]) { options[key] = value; } }); else return options[key]; } } //插件的名字 var methodName = "jqueryPluginName"; var options = {}; /** * 插件入口 */ $.fn.jqueryPluginName = function () { var method = arguments[0]; if (methods[method]) { method = methods[method]; arguments = Array.prototype.slice.call(arguments, 1); } else if (typeof method === "object" || !method) { method = methods.init; } else { $.error("Method(" + method + ") does not exist on " + methodName); return this; } return method.apply(this, arguments); } $.fn.jqueryPluginName.defaults = { }; })(jQuery);
标签:
原文地址:http://www.cnblogs.com/ccc3/p/4245515.html