Javascript,倒计时器和显示文本

时间:2012-04-03 07:56:42

标签: javascript html

我正在使用JavaScript制作倒数计时器。

这是我的剧本。

var seconds_left = 10;
var interval = setInterval(function() {
    document.getElementById('timer_div').innerHTML = --seconds_left;

    if (seconds_left <= 0)
    {
        //When it gets to 0 second, I want to show 'You are Ready!' text message.

    }
}, 1000);

从10秒钟开始算起。

我希望在0秒后消除秒数并显示“你准备好了!”消息。

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:23)

var seconds_left = 10;
var interval = setInterval(function() {
    document.getElementById('timer_div').innerHTML = --seconds_left;

    if (seconds_left <= 0)
    {
        document.getElementById('timer_div').innerHTML = 'You are ready';
        clearInterval(interval);
    }
}, 1000);

以下是Example

答案 1 :(得分:4)

document.getElementById('timer_div').innerHTML = "You are Ready!";

答案 2 :(得分:0)

<script>
    TargetDate = "12/31/2020 5:00 AM";
    DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    FinishMessage = "It is finally here!";
</script>
<script src="//scripts.hashemian.com/js/countdown.js"></script>