[英]bootstrap modal closes when ok on alert() is clicked
當我單擊“alert()”函數顯示的“確定”按鈕時,引導模式正在關閉。
$("#expample").modal({
backdrop: 'static',
keyboard: false,
show: true
});
下面是我的jQuery:
$('.sendToUser').on('click', function (){
var selectedLyrics = $('#selectedLyricsInput').val();
if($("input[name='selectUserRadio']").is(":checked") == false){
alert('Please, select a user to send.');
return;
}
});
雖然,在鍵盤上按“Enter”或“Esc”可以正常工作,也可以在模態之外單擊; 模態沒有關閉,這很好。
下面是我的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>
我正在從模式上的事件創建一個警報彈出窗口,但是當單擊警報()彈出窗口的“確定”時,它消失了。
單擊警報彈出窗口上的“確定”后如何防止關閉模式?
謝謝
您的模式正在關閉,因為.sendToUser
按鈕上有data-dismiss="modal"
屬性。 刪除此屬性應防止模式關閉。
您需要在.sendToUser
元素中刪除屬性data-dismiss="modal"
。
如果需要關閉modal,只需要添加代碼:
$('#userSelectionModal').modal('hide')
在你的腳本中使用
window.location = "..\path after validation"
還要避免在提交按鈕中使用data-dismiss="modal"
只需實例化一個與模式窗口內觸發的事件相關的變量 - 為false ,在認為必要時進一步將變量設置為false (例如,以防止在警報彈出時關閉模式),然后最后在窗口應該正常關閉時,做一個快速的“如果檢查”來評估變量是否最終為真,如果是,則啟動讓模態關閉的功能。 這確保模態窗口只有在您允許時才會關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.