JQuery插件的一般写法

(function($){
    //扩展这个方法到jQuery
    let Plugin = function(){

    }
    Plugin.prototype = {};
    $.fn.extend({
        //插件名字
        pluginname: function(options){
            let args = [].slice.call(arguments, 1);
            //遍历匹配元素的集合
            return this.each(function(){
                let ui = $._data(this, pluginname);
                if (!ui) {
                    let opts = $.extend(true, {}, $.fn.pluginname.defaults, typeof options === "object" ? options : {});
                    ui = new Plugin(opts, this);
                    $._data(this, pluginname, ui);
                }
                if (typeof options === "string" && typeof ui[options] === "function") {
                    ui[options].apply(ui, args);//执行插件的方法
                }
            });
        }
    });

    //默认配置
    $.fn.pluginname.defaults = {};

})(jQuery);
(function ($) {
    var ms = {
        init: function (obj, args) {
            return (function () {
                
            })();
        },
        //list li page
        listPage: function (obj, args) {
            
        },
        //动态添加html
        layoutHtml: function (obj, args) {
            return (function () {
                obj.empty();
                
                
            })();
        },
        //给分页、下一页、上一页绑定事件
        bindEvent: function (obj, args) {
            obj.unbind();
            return (function () {
                
            })();
        }
    }
    $.fn.createPaging = function (options) {
        var args = $.extend({
            pageCount: 30,
            currentPageCount: 30,
            current: 1
        }, options);
        ms.init(this, args);
    }
})(jQuery);
原文地址:https://www.cnblogs.com/KruceCoder/p/10231291.html