所以我正在做一个倒计时到零的javascript倒计时,然后切换div内的文本,以便用户可以继续。这是我的代码:
<div id="top">
You will be redirected in 10..
</div>
<script type="text/javascript">
$(document).ready(function(){
var timerId = 0;
if(timerId == 0){
timerId = window.setInterval(function() {
var timeCounter = 10;
var updateTime = parseInt(timeCounter,10) - 1;
$("#top").html("You will be redirected in " + updateTime + "...");
if(updateTime <= 0){
clearTimeout(timerId);
$("#top").html("Click to continue");
}
}, 1000);
}
});
</script>
它有效,但只能从 10 倒数到 9。这是为什么呢?