0
我有另一個問題。這次我想讓倒數計時器達到0時觸發或顯示一個模式窗口。讓倒數計時器顯示一個模態窗口引導程序
我有模式和倒數計時器的代碼,但我不知道如何完全使它,所以它要求的模態。
我已經嘗試了幾個我讀過的建議,但沒有任何作品或它只是螺絲代碼。
非常感謝提前。
var seconds = 300; //**change 120 for any number you want, it's the seconds **//
function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = "Last chance!";
} else {
seconds--;
}
}
var countdownTimer = setInterval('secondPassed()', 1000);
<!-- Modal start-->
<div class="modal fade" id="ventanamdl" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content"> <!-- to create more modals copy-paste from the div class "modal fade" until here, you can customize moda-content with css-->
<div class="modal-header">
<h1>This is your last chance!</h1>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<p>Your spot can't be reserved any longer! Click the button to join now!
<br>
<button id="btnjoin" type="submit" onclick="location.href='http://google.com';">Join!</button>
</p>
</div>
<div class="modal-footer">
This is your last chance!
</div>
</div>
</div>
</div>
<!-- Modal end-->
<div id="bottomdiv">
<p class="mytext2">Over 87 people have claimed their spot. Get yours before time runs out! <span id="countdown" class="timer"></span></p>
</div>
我試過這個,並設置計時器爲10秒來測試,但是在這10秒鐘過去後,模態沒有出現。但是謝謝你的幫助! 它可能也是我的模態HTML中的東西,我不得不明天檢查,因爲我很累。 – Revers3
你可以現在檢查。我編輯了答案。希望它會有所幫助。 –
它適合你嗎? –