切换显示:无基于工作日

时间:2017-10-31 09:44:10

标签: javascript

随着我的上一个问题被删除,我将尝试更具体地解决手头的问题。

我有一个名为budbox3的div类,这个div显示一个计时器,显示客户可以订购多长时间,并保证在同一天发货。

通过以下代码实现。

var timer = null;

   function tick( )
   {
var msg = document.getElementById("countdown");
var now = new Date();
var yr = now.getFullYear(); var mon = now.getMonth(); var dy = now.getDate();
var startat = new Date(yr,mon,dy,12,0,0);
var endat = new Date(yr,mon,dy,24,59,59);
if ( now.getTime() > endat.getTime() ) 
{
    startat.setDate( startat.getDate() + 1 ); // next game is tomorrow
}
if ( now.getTime() >= startat.getTime() && now.getTime() <= endat )
{
    msg.innerHTML = "";
} else {
    var sec = Math.floor( ( startat.getTime() - now.getTime() ) / 1000 );
    var min = Math.floor ( sec / 60 );
    sec %= 60;
    var hr = Math.floor ( min / 60 );
    min %= 60;
    if ( min < 10 ) min = "0" + min;
    if ( sec < 10 ) sec = "0" + sec;
    msg.innerHTML = hr + ":" + min + ":" + sec + " Endnu";
}
}
tick(); // immediate start
timer = setInterval( tick, 1000 ); // every second

现在我面临的挑战是让上述div类仅在工作日运行,因为我们目前无法在周末发送货物。

我尝试使用以下代码失败,也许有人可以提供帮助?

var now = new Date();
var day = now.getDay();

function SetDivContent() {

if (day==0||day==6) {
    $(".budbox3").css("display","none !important");
}
else if (day==1||day==2||day==3||day==4||day==5) {
    var timer = null;

    function tick( )
    {
        var msg = document.getElementById("countdown");
        var now = new Date();
        var yr = now.getFullYear(); var mon = now.getMonth(); var dy = now.getDate();
        var startat = new Date(yr,mon,dy,12,0,0);
        var endat = new Date(yr,mon,dy,24,59,59);
        if ( now.getTime() > endat.getTime() ) 
        {
            startat.setDate( startat.getDate() + 1 ); // next game is tomorrow
        }
        if ( now.getTime() >= startat.getTime() && now.getTime() <= endat )
        {
            msg.innerHTML = "";
        } else {
        var sec = Math.floor( ( startat.getTime() - now.getTime() ) / 1000 );
        var min = Math.floor ( sec / 60 );
        sec %= 60;
        var hr = Math.floor ( min / 60 );
        min %= 60;
        if ( min < 10 ) min = "0" + min;
        if ( sec < 10 ) sec = "0" + sec;
        msg.innerHTML = hr + ":" + min + ":" + sec + " Endnu";
        }
    }
    tick(); // immediate start
    timer = setInterval( tick, 1000 ); // every second
}
}

0 个答案:

没有答案