最近在用bootbox.js,发现弹出框没法自定义宽度,于是就看了源码,并改了源码
下面是修改之后的部分代码:
p.dialog = function (a) {a = h(a);var d = b(n.dialog),f = d.find(".modal-dialog"),i = d.find(".modal-body"),j = a.buttons,k = "",l = {onEscape: a.onEscape};f.css(a.boxCss);//后来添加,用于控制弹出框cssif (b.fn.modal === c) throw new Error("$.fn.modal is not defined; please double check you have included the Bootstrap JavaScript library. See /javascript/ for more details.");if (g(j, function (a, b) {k += "<button data-bb-handler='" + a + "' type='button' class='btn " + b.className + "'>" + b.label + "</button>", l[a] = b.callback}), i.find(".bootbox-body").html(a.message), a.animate === !0 && d.addClass("fade"), a.className && d.addClass(a.className), "large" === a.size ? f.addClass("modal-lg") : "small" === a.size && f.addClass("modal-sm"), a.title && i.before(n.header), a.closeButton) {var m = b(n.closeButton);a.title ? d.find(".modal-header").prepend(m) : m.css("margin-top", "-10px").prependTo(i)}return a.title && d.find(".modal-title").html(a.title), k.length && (i.after(n.footer), d.find(".modal-footer").html(k)), d.on("hidden.bs.modal", function (a) {a.target === this && d.remove()}), d.on("shown.bs.modal", function () {d.find(".btn-primary:first").focus()}), "static" !== a.backdrop && d.on("click.dismiss.bs.modal", function (a) {d.children(".modal-backdrop").length && (a.currentTarget = d.children(".modal-backdrop").get(0)), a.target === a.currentTarget && d.trigger("escape.close.bb")}), d.on("escape.close.bb", function (a) {l.onEscape && e(a, d, l.onEscape)}), d.on("click", ".modal-footer button", function (a) {var c = b(this).data("bb-handler");e(a, d, l[c])}), d.on("click", ".bootbox-close-button", function (a) {e(a, d, l.onEscape)}), d.on("keyup", function (a) {27 === a.which && d.trigger("escape.close.bb")}), b(a.container).append(d), d.modal({backdrop: a.backdrop ? "static" : !1,keyboard: !1,show: !1}), a.show && d.modal("show"), d}
下面是调用的代码:
bootbox.dialog({boxCss:{"width":"400px"},//这里添加了新的csstitle: "<span class='bigger-110'>确认审核</span>",message: "将key_value修改为:"+record.tempKeyValue+",原值:"+record.keyValue,buttons:{"success" :{"label" : "<i class='ace-icon fa fa-check'></i> 审核通过","className" : "btn-sm btn-success","callback": function() {$.post("system/system-audit",{id:v, isAudit:'1'},function(data){dataList.reload();alert(data.data);},"json");}},"danger" :{"label" : "审核不通过","className" : "btn-sm btn-danger","callback": function() {$.post("system/system-audit",{id:v, isAudit:'0'},function(data){dataList.reload();alert(data.data);},"json");}}}});
由于上面是代码混淆的,可能你们的代码和我的不大一样
下面链接是我改完的完整js,有需要的自行下载
下载地址