admin管理员组

文章数量:1415467

I am making a countdown timer with JavaScript.

Here is my script.

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);

It starts to count from 10 seconds.

I want to eliminate seconds when it gets 0 second and show a 'You are Ready!' message.

Can anyone help?

I am making a countdown timer with JavaScript.

Here is my script.

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);

It starts to count from 10 seconds.

I want to eliminate seconds when it gets 0 second and show a 'You are Ready!' message.

Can anyone help?

Share Improve this question edited Apr 4, 2012 at 7:18 stealthyninja 10.4k11 gold badges54 silver badges60 bronze badges asked Apr 3, 2012 at 7:56 JakeJake 2051 gold badge3 silver badges9 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 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);

Here is the Example

document.getElementById('timer_div').innerHTML = "You are Ready!";
<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>

本文标签: htmlJavascriptcountdown timer and display textStack Overflow