国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

【原創(chuàng)】基于Bootstrap的Modal二次封裝

2019-11-14 16:07:38
字體:
供稿:網(wǎng)友

前言

Bootstrap:Twitter推出的一個(gè)開源的用于前端開發(fā)的工具包。它由Twitter的設(shè)計(jì)師Mark Otto和Jacob Thornton合作開發(fā),是一個(gè)CSS/HTML框架

官方網(wǎng)站:http://www.bootcss.com/

1.Bootstrap Modals(模態(tài)框)基本用法

使用bootstrap之前需要應(yīng)用jquery.jsbootstrap.js以及bootstrap.css 注意:最新版的bootstrap需要和jquery1.9以上版本配合使用

    <!-- 按鈕觸發(fā)模態(tài)框 -->    <button class="btn btn-PRimary btn-lg" data-toggle="modal"            data-target="#myModal">        開始演示模態(tài)框    </button>    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"         aria-labelledby="myModalLabel" aria-hidden="true">        <div class="modal-dialog">            <div class="modal-content">                <div class="modal-header">                    <button type="button" class="close"                            data-dismiss="modal" aria-hidden="true">                        &times;                    </button>                    <h4 class="modal-title" id="myModalLabel">                        模態(tài)框(Modal)標(biāo)題                    </h4>                </div>                <div class="modal-body">                    在這里添加一些文本                </div>                <div class="modal-footer">                    <button type="button" class="btn btn-default"                            data-dismiss="modal">                        關(guān)閉                    </button>                    <button type="button" class="btn btn-primary">                        提交更改                    </button>                </div>            </div>        </div>    </div>

當(dāng)我們點(diǎn)擊button的時(shí)候會觸發(fā)Modal,效果如下圖所示

 2.0先看我們的封裝代碼

$(function () {    if ($.fn.modal) {        $.fn.modal.defaults.spinner = $.fn.modalmanager.defaults.spinner =    '<div class="loading-spinner" style="width: 200px; margin-left: -100px;">' +    '<div class="progress progress-striped active">' +      '<div class="progress-bar" style="width: 100%;"></div>' +    '</div>' +    '</div>';        $.fn.modalmanager.defaults.resize = true;    }    window.Modal = function () {        var _tplHtml = '<div class="modal created-modal" id="[Id]">' +                                        '<div class="modal-header">' +                                            '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>' +                                            '<h5 class="modal-title"><i class="icon-exclamation-sign"></i> [Title]</h5>' +                                        '</div>' +                                        '<div class="modal-body small">' +                                            '<p>[Message]</p>' +                                        '</div>' +                                        '<div class="modal-footer" >' +                                            '<button type="button" class="btn btn-primary ok" data-dismiss="modal">[BtnOk]</button>' +                                            '<button type="button" class="btn btn-default cancel" data-dismiss="modal">[BtnCancel]</button>' +                                        '</div>' +                            '</div>';        var _tplLoaDHTML = '<div class="modal created-modal" id="[Id]">' +                                                '<div class="modal-header">' +                                                    '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>' +                                                    '<h5 class="modal-title">[Title]</h5>' +                                                '</div>' +                                                '<div class="modal-body small">' +                                                    '<iframe src="[Url]" frameborder="0" width="100%" height="[Height]px" style="padding:0px; margin:0px;"></iframe>' +                                                '</div>' +                                        '</div>';        var reg = new RegExp("//[([^//[//]]*?)//]", 'igm');        var _alert = function (options) {            var id = _dialog(options);            var modal = $('#' + id);            modal.find('.ok').removeClass('btn-success').addClass('btn-primary');            modal.find('.cancel').hide();            return {                id: id,                on: function (callback) {                    if (callback && callback instanceof Function) {                        modal.find('.ok').click(function () { callback(true); });                    }                },                hide: function (callback) {                    if (callback && callback instanceof Function) {                        modal.on('hide.bs.modal', function (e) {                            callback(e);                        });                    }                }            };        };        var _confirm = function (options) {            var id = _dialog(options);            var modal = $('#' + id);            modal.find('.ok').removeClass('btn-primary').addClass('btn-success');            modal.find('.cancel').show();            return {                id: id,                on: function (callback) {                    if (callback && callback instanceof Function) {                        modal.find('.ok').click(function () { callback(true); });                        modal.find('.cancel').click(function () { callback(false); });                    }                },                hide: function (callback) {                    if (callback && callback instanceof Function) {                        modal.on('hide.bs.modal', function (e) {                            callback(e);                        });                    }                }            };        };        var _load = function (options) {            var ops = {                url: '',                title: '',                width: 800,                height: 550            };            $.extend(ops, options);            var modalId = _getId();            var html = _tplLoadHtml.replace(reg, function (node, key) {                return {                    Id: modalId,                    Title: ops.title,                    Url: ops.url,                    Height: ops.height                }[key];            });            $('body').append(html);            var modal = $('#' + modalId).modal({                width: ops.width            });            $('#' + modalId).on('hide.bs.modal', function (e) {                $(this).parent('.modal-scrollable').next().remove();                $(this).parent('.modal-scrollable').remove();                $('body').modalmanager('toggleModalOpen');            });        }        var _getId = function () {            var date = new Date();            return 'mdl' + date.valueOf();        }        var _dialog = function (options) {            var ops = {                msg: "提示內(nèi)容",                title: "操作提示",                btnok: "確定",                btncl: "取消",                width: 400,                auto: false            };            $.extend(ops, options);            var modalId = _getId();            var html = _tplHtml.replace(reg, function (node, key) {                return {                    Id: modalId,                    Title: ops.title,                    Message: ops.msg,                    BtnOk: ops.btnok,                    BtnCancel: ops.btncl                }[key];            });            $('body').append(html);            $('#' + modalId).modal({                width: ops.width,                backdrop: 'static'            });            $('#' + modalId).on('hide.bs.modal', function (e) {                //$(this).parent('.modal-scrollable').next().remove();                //$(this).parent('.modal-scrollable').remove();                $('body').modalmanager('toggleModalOpen');            });            return modalId;        }        var _cancelCheckbox = function () {            //設(shè)置取消樣式            $(".datagrid-header-check .checker").find("span").attr("class", "");//取消頭部第一個(gè)checkbox的樣式            $(".datagrid-cell-check .checker").find("span").attr("class", "");//取消列表選中checkbox的樣式            $(".datagrid-btable").find("tr").attr("class", "datagrid-row");//取消選中行的樣式            $(":checkbox:checked").attr("checked", false); //取消所有選中狀態(tài)        };        return {            alert: _alert,            confirm: _confirm,            load: _load,            cancelcheck: _cancelCheckbox,            loading: function () {                $('body').modalmanager('loading');            },            removeLoading: function () {                $('body').modalmanager('removeLoading');            }        }    }();});

3.0接下來看我們的案例代碼

@{    Layout = null;}//這里引入的文件要按照順序<script src="~/Scripts/jquery-1.8.2.min.js"></script><script src="~/Scripts/bootstrap/js/bootstrap.min.js"></script><script src="~/Scripts/bootstrap-modal/js/bootstrap-modal.js"></script><script src="~/Scripts/bootstrap-modal/js/bootstrap-modalmanager.js"></script><script src="~/Scripts/feng_modal.js"></script><link href="~/Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" /><link href="~/Scripts/bootstrap-modal/css/bootstrap-modal.css" rel="stylesheet" /><link href="~/Scripts/bootstrap-modal/css/bootstrap-modal-bs3patch.css" rel="stylesheet" /><!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title></head><body>    <div style="margin:500px" >         <button type="button" class="btn btn-primary" onclick="testalert()">測試alert</button>        <button type="button" class="btn btn-success" onclick="testload()">測試load</button>        <button type="button" class="btn btn-warning" onclick="testconfirm()">測試confirm</button>        <button type="button" class="btn btn-danger">測試</button>    </div></body></html><script type="text/javascript">    function testalert() {        Modal.alert({msg:"測試"});    }    function testload() {        Modal.load({ msg: "測試", url: "/Home/GetMsg/", title: "遠(yuǎn)程加載頁面", width: 1100, height: 650 });    }    function testconfirm() {        Modal.confirm({ msg: "確認(rèn)要加載嗎?" }).on(function (e) {            if (e) {                Modal.load({ msg: "測試", url: "/Home/GetMsg/", title: "遠(yuǎn)程加載頁面", width: 1100, height: 650 });            }        });    }</script>

4.0看我們達(dá)到的效果


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 托克托县| 大名县| 武汉市| 乐平市| 尖扎县| 白玉县| 慈利县| 青岛市| 大关县| 西青区| 天长市| 秭归县| 青州市| 唐河县| 澄城县| 永善县| 扎赉特旗| 南汇区| 青州市| 鹤庆县| 绥滨县| 中卫市| 邵阳市| 花莲县| 大埔县| 克拉玛依市| 上饶市| 神农架林区| 土默特左旗| 西充县| 芦山县| 鹤峰县| 五指山市| 札达县| 长寿区| 鹤峰县| 临安市| 浦北县| 怀柔区| 四子王旗| 华安县|