我无法捕获bootbox.confirm对话框的show事件,以便在显示之前对对话框进行一些css调整。
我尝试过类似以下的事情,但没有成功:
$(document).on("show.bs.modal", function (event) {...});
$(document).on("show", function (event) {...});
$(document).on("show", ".bootbox", function (event) {...});
答案 0 :(得分:40)
这应该适用于使用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) {...});
答案 1 :(得分:3)
我也更喜欢使用像:
这样的全局函数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');
答案 2 :(得分:2)
var dialog = bootbox.dialog("foo", [], {show: false});
dialog.on("shown", function() {
//
});
dialog.modal("show");