简体   繁体   English

如何获取此计时器以更新实时(Javascript)?

[英]How can I get this timer to update real time (Javascript)?

My mind is blank, any help would be amazing. 我的想法是空白,任何帮助都将是惊人的。 If I remove the seconds it will update every minute (which is good), but I don't want to lose using seconds. 如果我删除秒,它将每分钟更新一次(这很好),但是我不想浪费秒。 Updates on refresh (with seconds.) 刷新更新(以秒为单位)。

    var stopYear    = 2013;    /* the year (YYYY) to stop the count down */
var stopMonth   = 7;    /* the month (1-12) that we stop the count down */
var stopDay     = 14;    /* the day of the month (1-31) that we stop the count down */
var stopHour    = 17;    /* the number of hours (0-23) that we stop the count down*/
var stopMins    = 30;    /* the number of minutes (0-59) that we stop the count down */
var stopSeconds = 0;    /* the number of seconds (0-59) that we stop the count down */

/* build up the date that we are to stop the count down into a single date object */
var stopDate = new Date();
stopDate.setFullYear(stopYear,stopMonth-1,stopDay);
stopDate.setHours(stopHour,stopMins,stopSeconds);

function countDown() {
    var _milliseconds = stopDate - new Date();
    var _days = Math.round(_milliseconds/(86400000));
    _milliseconds = _milliseconds % (86400000);
    var _hours = Math.round(_milliseconds/(3600000));
    _milliseconds = _milliseconds % (3600000);
    var _minutes = Math.round(_milliseconds/(60000));
    _milliseconds = _milliseconds % (60000);
    var _seconds = Math.round(_milliseconds/(1000));
    var countDownText = 'The show is being played right now!';

    if (_minutes > 0) {
        _hours==24 ? _days= _days+1: _days=_days;
        _hours==24 ? _hours=0: _hours = _hours;//gm
        countDownText = _days + ' Day' + (_days!=1 ? 's ' : ' ');
        countDownText += _hours + ' hour' + (_hours!=1 ? 's and ' : ' and ');
        countDownText += _minutes + ' minute' + (_minutes!=1 ? 's ' : ' ');
        countDownText += _seconds + ' seconds' + (_seconds!=1 ? 's ' : ' ');
        countDownText += '.';
    } else {
        if (countDownHandle) clearInterval(countDownHandle);
    }
    document.getElementById('timeSenyu').innerHTML = countDownText;
}

var countDownHandle = null;
function startCountDown() {
    countDown();
    countDownHandle = setInterval('countDown()',60000);
}
onload = startCountDown;

Your setinterval function shouldn't reference countDown like that. 您的countDown函数不应像这样引用countDown Try setInterval(countDown, 60000) . 尝试setInterval(countDown, 60000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM