[英]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.