Hilios jQuery "The Final Countdown" Text After Count

时间:2015-07-31 20:01:52

标签: javascript jquery countdown

So, I am using Hilios jQuery "The Final Countdown", and I want to add a "Text After Countdown". To make it even better to understand what I want: when the countdown finishes (when the date comes), I don't want it to show 00:00:00:00 or something like that, but to change to text (from 00:00:00:00 to something like "Server Started"). I am no good at this jQuery/Javascript etc. stuff, so can someone help me?

I am using his "Timezone Aware" function/add-on, too.

2 个答案:

答案 0 :(得分:0)

As given in the documentation (http://hilios.github.io/jQuery.countdown/documentation.html#introduction)

You can use jQuery's on method for "finish.countdown" event to execute your code.

$('div#clock').countdown(finalDate)
    .on('update.countdown', callback)
    .on('finish.countdown', callback);

Here is JSFiddle example: https://jsfiddle.net/0yq3hbd2/1/

So in your case, it will be:

var currTime = new Date();

if (serverStart.toDate() < currTime)
    $('#clock').html("Server Started");
else
{
    $('#clock').countdown(serverStart.toDate(), function(event) { 
    $(this).html(event.strftime('%D:%H:%M:%S')); })
    .on('finish.countdown',function(event){$(this).html("Server Started");});
}

答案 1 :(得分:0)

只有一件事,外部if没用,因为当给定日期已经完成时,将调度完成事件。

其他改进是将updatefinish都注册为回调,就像上面连续执行两个finish事件一样,请改用:

$('#clock').countdown(serverStart.toDate())
.on('update.countdown', function(event) {
    $(this).html(event.strftime('%D:%H:%M:%S'));
})
.on('finish.countdown',function(event) {
    $(this).html("Server Started");
});

感谢您使用插件!