我正在做一个bootstrap网站,与一对bootstrap 'Modals'。 我正在尝试自定义一些默认功能。

问题在于; 你可以通过点击背景来关闭模式。 有没有办法禁用这个功能? 只在特定的情态动词?

引导模态页面


当前回答

如果你想更改默认值:

对于引导3.x:

$.fn.modal.prototype.constructor.Constructor.DEFAULTS.backdrop = 'static';
$.fn.modal.prototype.constructor.Constructor.DEFAULTS.keyboard =  false;

对于bootstrap 4。X和5.x:

$.fn.modal.prototype.constructor.Constructor.Default.backdrop = 'static';
$.fn.modal.prototype.constructor.Constructor.Default.keyboard =  false;

其他回答

对我来说有效的解决方法如下:

$('#myModal').modal({backdrop: 'static', keyboard: false})  

背景:禁用点击外部事件

键盘:禁用scape关键字事件

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.
})

TLDR

背景:‘静态’

https://getbootstrap.com/docs/3.3/javascript/#modals-options

为背景指定静态,它不会在单击时关闭模式。

根据你想要的屏幕宽度添加下面的css。

@media (min-width: 991px){
    .modal-dialog {
        margin: 0px 179px !important;
    }
}

有两种方法禁用自举模型区域之外的点击关闭模式

使用javascript $ (' # myModal ') .modal ({ 背景:“静态”, 键盘:假 }); 在HTML标签中使用data属性 data- background ="static" data-keyboard="false" //把这个属性写在你点击打开模态弹出窗口的按钮里。