zoukankan      html  css  js  c++  java
  • Juqery插件编写 基础说明

    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index3</title>
    
        <script src="/plugins/jquery/jquery-1.9.1.js"></script>
        <script type="text/javascript">
    
    
    
            $(function ($) { // 去除冲突
    
                // 实现$("#txt1").SpecialAlertTip({  300 });
                $.fn.SpecialAlertTip = function (options) {
    
                    var settings = {
                         100,
                        defalutText: "It is Default",
                        placeholder: 'Hello Jquery pulgIn',
                        showSearch: true,
                    }
                     // 合并  两个js对象  $.extend({name:1,23},{55});
                    settings = $.extend(settings, options);
    
                    /**
                    * Constructor
                    */
                    function SpecialAlertTip(select, settings) {
                        debugger;
                        this.$select = $(select);
                        this.settings = settings;
                        this.create();
                    }
    
    
                   /**
                  * Prototype class
                   * 获取:             ShipBusiness.origianlSelect = $("#CustomCargoRemarkV2").data("fSelect");
                   * 调用封装控件方法:   ShipBusiness.origianlSelect.reload();
                  */
                    SpecialAlertTip.prototype = {
                        create: function () {
                            debugger;
                            this.$select.css("width", this.settings.width + "px")
                            this.$select.css("border", "1px solid green");
                            this.$select.before('<div class="fs-label-wrap"><div class="fs-label">' + this.settings.placeholder + '</div><span class="fs-arrow"></span></div>');
                            this.$select.before('<div class="fs-dropdown hidden"><div class="fs-options"></div></div>');
                            this.reload();
                        },
    
                        reload: function () {
                            debugger;
                            if (this.settings.showSearch) {
                                var search = '<div class="fs-search"><input type="search" placeholder="' + this.settings.searchText + '" /></div>';
                                //this.$wrap.find('.fs-label-wrap').prepend(search);
                            }
                            //this.reloadDropdownLabel();
                        },
    
                        destroy: function () {
                            debugger;
    
                        }
                    }
    
    
                    /**
                     * Loop through each matching element
                     */
                    return this.each(function () {
                        debugger;
                        var data = $(this).data('SpecialAlertTip');
    
                        if (!data) {
                            data = new SpecialAlertTip(this, settings);
                            $(this).data('SpecialAlertTip', data);
                        }
    
                        if (typeof settings == 'string') {
                            data[settings]();
                        }
                    });
                }
    
            })
    
    
    
            // 使用新封装的 jquery控件
            $(document).ready(function () {
                $("#txt1").SpecialAlertTip({  300 });
                //如想调用 内部方法
                var speciallTxt = $("#txt1").data('SpecialAlertTip');
                speciallTxt.reload();
                speciallTxt.settings.showSearch = false;
            })
        </script>
    
    </head>
    <body>
        <div> 
            <div style="300px;border:1px solid silver;text-align:center;margin-bottom:10px;line-height:30px;font-size:18px;margin-left:auto;margin-right:auto;height:30px; "> jQuery 控件封装实例</div>
            <input type="text" id="txt1" />
        </div>
    </body>
    </html>
    

     

  • 相关阅读:
    系统分析员、系统架构师、项目经理的区别
    C# 委托(Delegate) 事件(Event)应用详解
    项目管理的通俗解释
    什么是依赖注入
    程序员每天该做的事
    鸿蒙应用开发入门(三):开发第一个鸿蒙应用
    #2020征文手机# 零基础鸿蒙开发4 如何播放一个全屏视频(JS版)
    【资源下载】快来获取HarmonyOS官方通用规范图标
    #2020征文手机# 快速搭建一款鸿蒙分布式分歧终端机原型
    #2020征文TV#鸿蒙应用开发TVHelloWord (二) 传递数据、跳转
  • 原文地址:https://www.cnblogs.com/liyanbofly/p/11419530.html
Copyright © 2011-2022 走看看