twitter-bootstrap 禁用 Bootbox 关闭按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24371565/
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 21:00:21  来源:igfitidea点击:

Disable the Bootbox close button

javascripttwitter-bootstrapbootbox

提问by Ectropy

I'm wondering how remove the "X" button that shows up on Bootboxalerts, confirms, prompts and dialogs.

我想知道如何删除出现在Bootbox警报、确认、提示和对话框中的“X”按钮。

There are cases where you'd wish to require the user to provide a response--not just dismiss the pop-up with a click on the "X" button.

在某些情况下,您希望要求用户提供响应——而不仅仅是通过单击“X”按钮来关闭弹出窗口。

Does anyone have an idea of how to remove this button?

有没有人知道如何删除这个按钮?

回答by Ectropy

I ended up finding the solution, and it is fairly easy (but doesn't seem to be in the current Bootbox documentation.)

我最终找到了解决方案,它相当简单(但似乎不在当前的 Bootbox 文档中。)

The solution works for Bootbox Dialogs, so if you need to remove the "X" for other types of boxes, I'd suggest imitating the other, more primitive types of boxes as a dialog.

该解决方案适用于引导框对话框,因此如果您需要删除其他类型框的“X”,我建议将其他更原始类型的框模仿为对话框。

The solution, which uses closeButton: false, is seen in the snippet below:

使用 的解决方案closeButton: false见下面的片段:

        bootbox.dialog({
            closeButton: false,
            title: "Woah this acts like an alert",
            message: "Cool info for you. You MUST click Ok.",
            buttons: {
                success:{
                    label: "Ok",
                    callback: callback
                }
            }       
        });

       callback(){//stuff that happens when they click Ok.}

By making sure the user must click on a button to dismiss the box, we can make sure they trigger an appropriate callback function.

通过确保用户必须单击按钮才能关闭该框,我们可以确保他们触发了适当的回调函数。