本文翻译自:Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape? [duplicate]
I'm using the Twitter Bootstrap modal as a wizard window, and would like to prevent the user from closing it when clicking outside of the modal or when pressing escape. 我将Twitter Bootstrap模态用作向导窗口,并希望防止用户在模态之外单击或按Escape键时将其关闭。 Instead, I want it to be closed when the user presses the finish button. 相反,我希望在用户按下“完成”按钮时将其关闭。 How could I achieve this scenario? 我如何实现这种情况?
#1楼
参考:https://stackoom.com/question/15ltJ/防止在单击外部或按Escape键时Bootstrap-Modal消失-重复
#2楼
If using JavaScript then: 如果使用JavaScript,则:
$('#myModal').modal({
backdrop: 'static',
keyboard: false
})
or in HTML: 或使用HTML:
<a data-controls-modal="your_div_id" data-backdrop="static" data-keyboard="false" href="#">
#3楼
也可以使用,在您的div模式中,单击data-backdrop="static"
可以单击出,然后将data-keyboard="false"
移至Esc:
<div id="idModal" class="modal hide" data-backdrop="static" data-keyboard="false">
#4楼
You can use the code below 您可以使用以下代码
$.fn.modal.prototype.constructor.Constructor.DEFAULTS.backdrop = 'static';
to change the default behavior. 更改默认行为。
#5楼
If you need disable clicking outside but enable pressing escape 如果您需要禁用单击外部但启用按Escape键
$('#myModal').modal({ backdrop: 'static', // This disable for click outside event keyboard: true // This for keyboard event })
#6楼
Your code is working when i click out side the modal, but if i use html input
field inside modal-body then focus your cursor on that input then press esc
key the modal has closed. 当我在模态之外单击时,您的代码正在工作,但是如果我在模态主体内使用html input
字段,则将光标放在该输入上,然后按esc
键,模态已关闭。 Click here 点击这里