【发布时间】:2017-08-21 04:17:13
【问题描述】:
我还有一个问题。这次我想让它在倒数计时器达到 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>
【问题讨论】:
标签: javascript jquery timer modal-dialog countdown