禁用在bootstrap模态区域外单击以关闭模态 [英] Disable click outside of bootstrap modal area to close modal
问题描述
我正在制作一个引导程序网站,其中包含几个Bootstrap'Modals'。
我正在尝试自定义一些默认功能。
I am making a bootstrap website, with a couple of Bootstrap 'Modals'. I'm trying to customize some of the default features.
问题是这样;
您可以通过单击背景关闭模态。
无论如何都要禁用此功能?
仅限于特定模式?
Problem is this; You can close the modal by clicking on the background. Is there anyway to disable this feature? On specifc modals only?
推荐答案
在选项章节中,在您链接的页面中,您可以看到背景
选项。使用值'static'
传递此选项将阻止关闭模式。
由于@PedroVagner指向评论,您也可以传递 {keyboard:false}
通过按 Esc 来阻止关闭模态。
On Options chapter, in the page you linked, you can see the backdrop
option. Passing this option with value 'static'
will prevent closing the modal.
As @PedroVagner pointed on comments, you also can pass {keyboard: false}
to prevent closing the modal by pressing Esc.
如果你用js打开模态,请使用:
If you opening the modal by js use:
$('#myModal').modal({backdrop: 'static', keyboard: false})
如果您正在使用数据属性,请使用:
If you are using data attributes, use:
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
Launch demo modal
</button>`
这篇关于禁用在bootstrap模态区域外单击以关闭模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!