我一直有一些JQuery代碼的問題。 我試圖做一個「動態」的網站,所以每次你點擊一個鏈接('一個'元素有一個'鏈接'屬性),我的代碼需要'鏈接'屬性並將其傳遞給jQuery的load()功能。事情是,我想讓用戶知道內容正在加載,所以我想我可以在開始加載之前顯示一個模式,並在完成時隱藏它,但它不起作用。我第一次點擊一個鏈接時,模態停留在那裏,並且不會消失。但是,從第二次開始,我點擊任何鏈接,一切都完美無缺。從jQuery隱藏bootstrap模式不會工作第一次
爲什麼它只是第一次關閉?
$(document).on("click", "[link]", function() {
$("#cargando").modal('show');
$('#contenido').load($(this).attr('link'), function() {
$('#cargando').modal('hide');
$('.modal-backdrop').hide();
});
});
額外的信息:這個代碼和HTML模式是一起在一個名爲dyn.html文件,該文件包括在頁面的其餘部分的結束。
編輯,模態代碼:
<div class="modal modal-static fade" id="cargando">
<div class="modal-dialog"><div class="modal-content">
<div class="modal-body"><div class="text-center">
<h4>Cargando...</h4>
</div></div></div></div></div>
編輯,它適用於:
$(document).on("click", "[link]", function() {
$('#cargando').modal('show');
$('#contenido').load($(this).attr('link'), function() {
$('#cargando').hide();
$('.modal').hide();
$('.modal-backdrop').hide();
});
});
它的混亂,但它是工作的第一件事。
你可以嘗試將'modal('show')'和'modal('hide')'替換爲'modal('toggle')'嗎? –
它現在加載兩個模態。每次。有時超過兩個。 –
你能提供一個鏈接到你的網站,或在小提琴中重現嗎? –