0

我的网站上有倒计时,我希望它倒计时到下周五,当周五结束时,我希望它自动倒计时到下周五.. 重复一遍..

我有这个脚本,但似乎无法让它工作,有人可以帮我吗?

提前致谢

$(function(){

var note = $('#note'),
    ts = new Date(5), //Setting the date here
    newYear = true;

if((new Date()) > ts){
    ts = (new Date()).getTime() + 10*24*60*60*1000;
    newYear = false;
}

$('#countdown').countdown({
    timestamp   : ts,
    callback    : function(days, hours, minutes, seconds){

        var message = "";

        message += days + " day" + ( days==1 ? '':'s' ) + ", ";
        message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
        message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
        message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";

        if(newYear){
            message += "left until the new year!";
        }
        else {
            message += "left to 10 days from now!";
        }

        note.html(message);
    }
});

});
4

1 回答 1

2

使用 Date 对象上存在的 getDay() 方法,该方法将返回天数 0 = 星期日,1 = 星期一,5 = 星期五。
确定今天是哪一天,距离下一天还有多少天 5.
然后 ts = (new Date()).getTime() + 60*60*24*daysUntilFriday*1000;
在此之后,您还希望使用方法 setHours()、setMinutes() 和 Seconds 为 0,以便获得周五开始之前的准确时间。

EDIT! Sorry when you are done with your ts variable you want to use setTime(ts) so that you get a new Date object with the next Fridays date. And then you start setting hours, minutes and seconds to zero and then getTime() again so that your ts is the correct format for your countdown method.

Good luck!

Regards Tobias

于 2012-08-22T14:13:08.457 回答