Bootbox 封装 拿过去直接用不谢
(function ($) { $.systemBootBox = function (options) { var opts = $.extend({}, $.systemBootBox.defaults, options); var tokenTime = new Date().getTime(); $.cookie('hf_token', tokenTime); //设置cookie if (opts.boxType == 'alert') { bootbox.alert({ size: opts.size, title: opts.title, message: opts.message, callback: function (data) { opts.boxCallback(data); }, //buttons: { // OK: { // label: '<i class="fa fa-check"></i> 确定', // className: 'btn-info', //按钮颜色 // } //} }); } if (opts.boxType == 'confirm') { bootbox.confirm({ size: opts.size, message: opts.message, buttons: { cancel: { label: '<i class="fa fa-times"></i> 取消', className: 'btn-danger', }, confirm: { label: '<i class="fa fa-check"></i> 确定', className: 'btn-info', //按钮颜色 } }, callback: function (data) { opts.boxCallback(data); } }) } if (opts.boxType == 'dialog') { bootbox.dialog({ size: opts.size, title: opts.title, message: '<form id="DataForm" action="" class="form-style">' + opts.message + '<input name="token" type="hidden" value="' + tokenTime + '"/></form>', complete: function () { opts.onComplete(); }, buttons: { cancel: { label: '<i class="fa fa-times"></i> 取消', className: 'btn-danger', callback: function () { // Example.show('Custom cancel clicked'); } }, ok: { label: '<i class="fa fa-check"></i> 确定', className: 'btn-info', //按钮颜色 callback: function (data) { opts.boxCallback(data); if (opts.closeOrShow == false) { return false; } } } } }); } } $.hideModel = function () { $('.bootbox').modal('hide'); } $.systemBootBox.defaults = { boxType: '',//alert ,confirm,diolog 弹出框 ,警告框,自定义对话框 size: null, // large ,small title: "标题演示", message: "标题信息演示", onComplete: function () { }, onEscape: true, //Esc 关闭对话框 show: false,//立即显示对话框 closeButton: false, //关闭按钮 boxCallback: function (data) { alert(data); }, //回调函数 closeOrShow: false, //true 关闭 false 不关 dialogInt: function () { }, //初始化执行函数 }; })(jQuery); //调用 $.systemBootBox({ title: titleMsg, boxType: 'dialog', message: $('#hf_window').html(), boxCallback: function (data) { edit(); } }); //关闭模态框; $.hideModel(); 默认点击确定不关闭模态框,可修改封装里面为True //修改源码 bootbox.js var defaults = { // default language locale: "en", // show backdrop or not. Default to static so user has to interact with dialog backdrop: "static", // animate the modal in/out animate: true, // additional class string applied to the top level dialog className: null, // whether or not to include a close button closeButton: true, // show the dialog immediately by default show: true, complete: function () { }, // dialog container container: "body" };