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

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

引导模态页面


当前回答

将此CSS用于模态和模态对话框

.modal{
    pointer-events: none;
}

.modal-dialog{
    pointer-events: all;
 }

这可以解决您在Modal中的问题

其他回答

你可以使用

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

更改默认行为。

你可以像这样使用一个属性:data- background ="static"或者使用javascript:

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false  // to prevent closing with Esc button (if you want this too)
})

也可以看到这个答案:禁止twitter引导模式窗口关闭

你也可以不使用JQuery做到这一点,如下所示:

<div id="myModal">

var modal = document.getElementById('myModal');
modal.backdrop = "static";
modal.keyboard = false;

将此CSS用于模态和模态对话框

.modal{
    pointer-events: none;
}

.modal-dialog{
    pointer-events: all;
 }

这可以解决您在Modal中的问题

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