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>
    

     

  • 相关阅读:
    三种方法处理文字中的空格
    text——文本属性大全
    font——文字属性大全
    padding和margin——内边距和外边距
    background——背景属性
    C# 解析excel时,字段内有内容,却读取不到的解决方法
    jqprint 打印分页
    pre标签 首行会自动换行解决方案
    正则表达式 清除所有标签的属性
    针对安卓微信浏览器网页 置顶悬浮框浮动固定 的问题
  • 原文地址:https://www.cnblogs.com/liyanbofly/p/11419530.html
Copyright © 2011-2022 走看看