Javascript倒计时 - 需要单独的过期消息

时间:2013-07-05 21:14:27

标签: javascript timer

我妈妈要求我更改倒数计时器到期日期。她目前有一个使用php的后端功能,可以更改日期。有两个柜台并排用于草莓,然后一个用于玉米。我需要在标签过期时更改标签。现在他们是同一个标签。

我在下面更改了“已过期”到“草莓季已结束”的文字正确显示。问题是,当玉米到期时,它将显示“草莓季节结束”。这是不正确的,因为它是玉米。所以我希望有两个单独的标签。

else 
{ 
    cCtn.innerHTML = label + " Strawberry Season Has Ended"; 
}

这是整个编码,包括DIV布局和PHP。

<div style="position:relative; top:0px; float:left; padding-left:10px; color:#790108; text-align:left; font-size:16px; background:url(img/counterBG.jpg) no-repeat; width:632px; margin-left:14px; height:120px;">
    <div style="width:300px; position:absolute; top:38px; text-align:center; ">
        <label style="color:#000; font-size:18px;">Strawberry Countdown Timer</label>
        <br>
        <span id='clockCtnSB'></span>
    </div>                      
    <div style="width:300px; position:absolute; top:38px; left: 330px; text-align:center; ">
        <label style="color:#000; font-size:18px;">Corn Countdown Timer</label>
        <br>
        <span id='clockCtnC'></span>
    </div>                                              

PHP:

<?php
$clsDB->where = "`rec_id`=2";
$rec_counter = $clsDB->firstRec('counter_dates');
$counterStrawBerries = $rec_counter['date'];
$clsDB->where = "`rec_id`=1";
$rec_counter = $clsDB->firstRec('counter_dates');
$counterCorn = $rec_counter['date'];
$timestampSB = strtotime($counterStrawBerries);
$timestampC = strtotime($counterCorn);
?>

使用Javascript:

function timeTm( span, date, label ) 
{
    var cCtn = document.getElementById(span);

    if (cCtn) 
    {
        var ev = date;
        var vr = new Date();
        var diffE = ev - vr;

        if (diffE > 0) 
        {
            var dy = Math.floor(diffE/(1000*3600*24));
            var diffC = diffE - (dy * 1000 * 3600 * 24);

            if (hr==0 && mn==0) 
                dateTm();
            cCtn.innerHTML = "";

            if (dy == 1) 
            {
                cCtn.innerHTML += dy + " Day " } else if(dy > 1) { cCtn.innerHTML += dy + " Days " 
            }
            var hr = Math.floor(diffC/(1000*3600));
            var mn = Math.floor((diffC - (hr*1000*3600))/(1000*60));
            var sc = Math.floor((diffC - (hr*1000*3600) - (mn*1000*60))/1000);

            if (hr<10) 
            { 
                cCtn.innerHTML+="0" + hr; 
            } 
            else 
            { 
                cCtn.innerHTML += hr; 
            } 
            cCtn.innerHTML += " Hours ";

            if (mn<10) 
            { 
                cCtn.innerHTML += "0" + mn; 
            } 
            else 
            { 
                cCtn.innerHTML += mn; 
            } 
            cCtn.innerHTML+=" Minutes ";
        } 
        else 
        { 
            cCtn.innerHTML = label + " Strawberry Season Has Ended"; 
        }
         setTimeout("startDateTime()", 60000);
    }
}

function startDateTime() 
{ 
    timeTm('clockCtnSB', 
        new Date(<?php echo date("Y", $timestampSB); ?>,
        <?php echo date("m", $timestampSB) - 1 ?>,
        <? echo date("d", $timestampSB); ?>, 0, 0), "");

    timeTm('clockCtnC',
        new Date(<?php echo date("Y", $timestampC); ?>,
        <?php echo date("m", $timestampC) - 1 ?>,
      <? echo date("d", $timestampC); ?>, 0, 0), "" );
}

startDateTime();

0 个答案:

没有答案