我正在做一个bootstrap网站,与一对bootstrap 'Modals'。 我正在尝试自定义一些默认功能。
问题在于; 你可以通过点击背景来关闭模式。 有没有办法禁用这个功能? 只在特定的情态动词?
引导模态页面
我正在做一个bootstrap网站,与一对bootstrap 'Modals'。 我正在尝试自定义一些默认功能。
问题在于; 你可以通过点击背景来关闭模式。 有没有办法禁用这个功能? 只在特定的情态动词?
引导模态页面
当前回答
如果你想禁用所有使用jQuery的模态的外部点击,使用这个。在jQuery之后添加这个脚本到你的Javascript。
jQuery(document).ready(function () {
jQuery('[data-toggle="modal"]').each(function () {
jQuery(this).attr('data-backdrop','static');
jQuery(this).attr('data-keyboard','false');
});
});
其他回答
根据你想要的屏幕宽度添加下面的css。
@media (min-width: 991px){
.modal-dialog {
margin: 0px 179px !important;
}
}
这是最简单的
你可以定义你的模式行为,定义数据键盘和数据背景。
<div id="modal" class="modal hide fade in" data-keyboard="false" data-backdrop="static">
You can Disallow closing of #signUp (This should be the id of the modal) modal when clicking outside of modal.
As well as on ESC button.
jQuery('#signUp').on('shown.bs.modal', function() {
jQuery(this).data('bs.modal').options.backdrop = 'static';// For outside click of modal.
jQuery(this).data('bs.modal').options.keyboard = false;// For ESC button.
})
试试这个:
<div
class="modal fade"
id="customer_bill_gen"
data-keyboard="false"
data-backdrop="static"
>
在Options一章中,在您链接的页面中,您可以看到背景选项。通过这个值为static的选项将阻止关闭模态。 正如@PedroVagner在评论中指出的那样,你也可以通过传递{keyboard: false}来防止按Esc关闭模态。
如果你用js打开模态,使用:
$('#myModal').modal({backdrop: 'static', keyboard: false})
如果您正在使用数据属性,请使用:
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
Launch demo modal
</button>`