我无法捕获bootbox.confirm对话框的show事件,以便在显示它之前进行一些CSS调整。
我尝试了以下方法,但并没有成功:
$(document).on("show.bs.modal", function (event) {...});
$(document).on("show", function (event) {...});
$(document).on("show", ".bootbox", function (event) {...});
我无法捕获bootbox.confirm对话框的show事件,以便在显示它之前进行一些CSS调整。
我尝试了以下方法,但并没有成功:
$(document).on("show.bs.modal", function (event) {...});
$(document).on("show", function (event) {...});
$(document).on("show", ".bootbox", function (event) {...});
这应该适用于您使用的Bootbox 4.x.x和Bootstrap 3.x.x:
var box = bootbox.dialog({
message: '',
title: '',
buttons: {},
show: false
});
box.on("shown.bs.modal", function() {
alert('it worked!');
});
box.modal('show');
或者像这样:
$(document).on("shown.bs.modal", function (event) {...});
我更喜欢使用全局函数,例如:
function bootbox_confirm(msg, callback_success, callback_cancel) {
var d = bootbox.confirm({message:msg, show:false, callback:function(result) {
if (result)
callback_success();
else if(typeof(callback_cancel) == 'function')
callback_cancel();
}});
d.on("show.bs.modal", function() {
//css afjustment for confirm dialogs
alert("before show");
});
return d;
}
并以这种方式调用:
bootbox_confirm("my message", function(){alert('ok')}, function(){alert('cancel')}).modal('show');
或者当没有取消逻辑时:
bootbox_confirm("my message", function(){alert('ok')}).modal('show');
var dialog = bootbox.dialog("foo", [], {show: false});
dialog.on("shown", function() {
//
});
dialog.modal("show");
box.modal('show')
显示模态框,则show.bs.modal事件也会被触发。 - rolandow