简体   繁体   English

如果用户单击其他任何地方,Bootstrap 模式将被关闭..如何防止这种情况发生?

[英]Bootstrap modal dismiss if user click anywhere else..how to prevent this?

I am using Twitter's Bootstrap modal.我正在使用 Twitter 的 Bootstrap 模式。

The modal is dismissed whenever the user clicks anywhere else on the screen except the modal.每当用户单击屏幕上除模态框以外的任何其他位置时,模态框就会消失。

Is there a way I can prevent this, so the user has to click the Close button to dismiss the modal?有什么办法可以防止这种情况发生,因此用户必须单击“关闭”按钮才能关闭模态吗?

Best,最好,

you can pass these options: 你可以传递这些选项:

{
  keyboard: false,
  backdrop: 'static'
}

In most cases, the modal dialog is constructed not using Javascript, rather it's using the markup, in this scenario, just add attribute: data-backdrop="static" in the div that has class="modal fade". 在大多数情况下,模态对话框不是使用Javascript构建的,而是使用标记,在这种情况下,只需在具有class =“modal fade”的div中添加属性:data-backdrop =“static”。

Example: 例:

  <div class="modal fade" id="myModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

In some cases, this alternative solution may be useful. 在某些情况下,这种替代解决方案可能是有用的。

$('#modalElement').on('hide.bs.modal', function () {
    return false;
});

For new version of bootstrap at least 5.0 the correct way is:对于至少 5.0 的新版引导程序,正确的方法是:

 <div class="modal fade" id="carDialog" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="carDialogLabel" aria-hidden="true">

Take a look at backdrop and keyboard it is: data-bs-backdrop and data-bs-keyboard.看一下背景和键盘:data-bs-backdrop 和 data-bs-keyboard。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果用户单击任意位置,如何销毁引导程序 - How to destroy a bootstrap if user click anywhere 如何在UI网格角单击时关闭引导程序模态 - How to dismiss bootstrap modal on click in ui grid angular 单击模式对话框中的其他任何位置以关闭下拉列表 - Click anywhere else in modal dialog in order to close a dropdown list 如果浏览器中没有操作,如何关闭引导模式 - How to dismiss bootstrap modal if no action in browser 如何通过从页面上的任何地方(其他地方)单击来关闭 Twitter Bootstrap 弹出窗口? - How can I close a Twitter Bootstrap popover with a click from anywhere (else) on the page? 如何在引导缩略图上添加工具提示,并在用户单击其他任何地方时再次使其不可见 - How to add a tooltip to the bootstrap thumbnail and make it invisible again when the user clicks anywhere else Data-Dismiss:如何在 function 中关闭引导模式 - Data-Dismiss: How to dismiss bootstrap modal inside function 在引导程序中触发两个模态时,如何消除其中一个模态 - how to dismiss one of the modal, when triggered two modal in the bootstrap 引导程序的模态-单击取消按钮-触发`close()`或`dismiss()`吗? - Bootstrap's modal - click on cancel button - trigger `close()` or `dismiss()`? 无法通过背景幕点击关闭自定义UI引导模式 - Can't dismiss custom UI Bootstrap modal by backdrop click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM