zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    Redis
    多线程相关
    selenium操作浏览器的基本方法
    selenium之 webdriver与三大浏览器版本映射表(更新至v2.29)
    selenium安装及官方文档
    Python(3)_python对Json进行操作
    python类中的self参数和cls参数
    python3中shuffle函数
    Python3中assert断言
    python2和python3中range的区别
  • 原文地址:https://www.cnblogs.com/KruceCoder/p/10231291.html
Copyright © 2011-2022 走看看