twitter-bootstrap 使用 bootbox 不会触发 show 事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23198453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:32:50  来源:igfitidea点击:

Using bootbox the show event is not fired

jquerytwitter-bootstrapbootbox

提问by alloyoussef

I'm not able to catch the show event for the bootbox.confirm dialog in order to do some css adjustments to the dialog before showing it.

我无法捕获 bootbox.confirm 对话框的 show 事件,以便在显示之前对对话框进行一些 css 调整。

I tried things like the followings but didn't succeed:

我尝试了以下操作,但没有成功:

$(document).on("show.bs.modal", function (event) {...});
$(document).on("show", function (event) {...});
$(document).on("show", ".bootbox", function (event) {...});

采纳答案by alloyoussef

I would also prefer to use a global function like:

我也更喜欢使用全局函数,如:

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;
}

and call it this way:

并这样称呼它:

bootbox_confirm("my message", function(){alert('ok')}, function(){alert('cancel')}).modal('show');

or when no logic for cancel:

或者当没有取消逻辑时:

bootbox_confirm("my message", function(){alert('ok')}).modal('show');

回答by codephobia

This should work for you using Bootbox 4.x.x and Bootstrap 3.x.x:

这应该适用于使用 Bootbox 4.xx 和 Bootstrap 3.xx 的你:

var box = bootbox.dialog({
  message: '',
  title: '',
  buttons: {},
  show: false
});

box.on("shown.bs.modal", function() {
  alert('it worked!');
});

box.modal('show');

or like this:

或者像这样:

$(document).on("shown.bs.modal", function (event) {...});

回答by Nayeem Mansoori

you can do like this:

你可以这样做:

var dialog = bootbox.dialog("foo", [], {show: false});

dialog.on("shown", function() {
 //
});

dialog.modal("show");