[英]bootstrap modal closes when ok on alert() is clicked
Bootstrap modal is closing when I click on "Ok" button showing from "alert()" function.当我单击“alert()”函数显示的“确定”按钮时,引导模式正在关闭。
$("#expample").modal({
backdrop: 'static',
keyboard: false,
show: true
});
Below is my jquery:下面是我的jQuery:
$('.sendToUser').on('click', function (){
var selectedLyrics = $('#selectedLyricsInput').val();
if($("input[name='selectUserRadio']").is(":checked") == false){
alert('Please, select a user to send.');
return;
}
});
Although, hitting "Enter" or "Esc" on keyboard is working fine and also, clicking outside the modal;虽然,在键盘上按“Enter”或“Esc”可以正常工作,也可以在模态之外单击; the modal is not closing which is fine.
模态没有关闭,这很好。
Below is my html:下面是我的html:
<div class="modal fade" id="userSelectionModal" tabindex="-1" role="dialog" aria-labelledby="userSelectionModal">
<div class="modal-dialog modal-likes" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Select User</h4>
</div>
<div class="modal-body">
<div style="margin-bottom: 50px;" id="populateUsers">
</div>
<input type="hidden" id="selectedLyricsInput" value="" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success sendToUser" data-dismiss="modal">Send</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
{{--<i class="fa fa-spinner fa-spin"></i>--}}
</div>
</div>
</div>
I am creating an alert popup from an event on the modal but when clicked on the "ok" of the alert() popup, it disappears.我正在从模式上的事件创建一个警报弹出窗口,但是当单击警报()弹出窗口的“确定”时,它消失了。
How to prevent closing of the modal after clicking on "OK" on the alert popup?单击警报弹出窗口上的“确定”后如何防止关闭模式?
Thanks谢谢
Your modal is closing, because you have data-dismiss="modal"
attribute on the .sendToUser
button.您的模式正在关闭,因为
.sendToUser
按钮上有data-dismiss="modal"
属性。 Removing this attribute should prevent the modal from closing.删除此属性应防止模式关闭。
You need to remove attribute data-dismiss="modal"
at the .sendToUser
element.您需要在
.sendToUser
元素中删除属性data-dismiss="modal"
。
If you need to close modal, you just need to add the code:如果需要关闭modal,只需要添加代码:
$('#userSelectionModal').modal('hide')
use within your script在你的脚本中使用
window.location = "..\path after validation"
also avoid data-dismiss="modal" in submit button还要避免在提交按钮中使用data-dismiss="modal"
Simply instantiate a variable that's tied to the events firing within the modal window - to false , further set the variable to false when deemed necessary (eg to prevent closing the modal when the alert pops up), and then finally when the window should normally close, do a quick "if check" that assesses if the variable is finally true and if it is, fire off the functionality that lets the modal close.只需实例化一个与模式窗口内触发的事件相关的变量 - 为false ,在认为必要时进一步将变量设置为false (例如,以防止在警报弹出时关闭模式),然后最后在窗口应该正常关闭时,做一个快速的“如果检查”来评估变量是否最终为真,如果是,则启动让模态关闭的功能。 This ensures that the modal window will close only when you allow it.
这确保模态窗口只有在您允许时才会关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.