zoukankan      html  css  js  c++  java
  • jquery弹出层控件

    (function($) {
        // 插件的定义
        // var opts;
        $.fn.modelwindow = function(options) {
            debug(this);
            // build main options before element iteration
            opts = $.extend({}, $.fn.modelwindow.defaults, options);

            $("#contentdiv").css({ display: "none" });
            // iterate and reformat each matched element     
            this.each(function() {

                //  var markup = $this.html();
                // call our format function

                $(this).click(function() {
                    $("#contentdiv").html(showdiv($(this).attr("href")), opts);
                    $("#contentdiv").fadeIn(700)
                    return false;
                });

            });
        };
        // 私有函数:debugging     
        function debug($obj) {
            if (window.console && window.console.log)
                window.console.log('modelwindow selection count: ' + $obj.size());
        };
        // 定义暴露format函数     
        $.fn.modelwindow.format = function(txt) {
            return '<strong>' + txt + '</strong>';
        };
        // 定义弹出层函数
        showdiv = function(url, opts) {
            return '<div id="maskdiv" onclick="modelwindowhidden()"></div><div id="showdiv" ><div class="showdivbar"><a href="#" class="showdivbarclose" onclick="modelwindowhidden(opts)">close</a></div><iframe name="iframe" id="iframe" src=' + url + ' width="100%" height="500" /></div>';
        };
        //隐藏窗口
        modelwindowhidden = function(opts) {
             
            var d = $("#iframe").contents().find(opts.callbackcontentid).val();
            opts.callback;
            opts.onclosed(d);
           
            $('#contentdiv').fadeOut(700);
            $('#contentdiv').html("");

           
        }
        // 插件的defaults     
        $.fn.modelwindow.defaults = {
            foreground: 'red',
            background: 'yellow',
            callback: {},
            onclosed: {},
            callbackcontentid: ""

        };
        // 闭包结束     
    })(jQuery);     
     
     
    调用方法
    $(document).ready(function() {
         $("a").modelwindow({
          onclosed: function(data) { $("#cb").val(data); },
          callbackcontentid: "#Text4"

        })
    })
  • 相关阅读:
    jdbc连接数据库 url
    解决IntelliJ IDEA 使用 TOMCAT 中文乱码问题
    web.xml 4.0 头部信息
    jar包冲突解决方案
    idea 快捷键
    基于单片机的车辆防碰撞及自动刹车系统(STC89C52RC芯片+超声波传感器HC-SR04+液晶屏1602+继电器+蜂鸣器)
    电子时钟万年历+51单片机+1602液晶屏+DS1302+DS18B20+按键
    1008 数组元素循环右移问题(PAT)
    1007 素数对猜想(PAT)
    1006 换个格式输出整数(PAT)
  • 原文地址:https://www.cnblogs.com/mz121star/p/2250493.html
Copyright © 2011-2022 走看看