我怎样才能让这个计时器实时更新(Javascript)
How can I get this timer to update real time (Javascript)?
我的脑子一片空白,任何帮助都会很棒。如果我删除秒数,它将每分钟更新一次(这很好(,但我不想丢失使用秒数。刷新时更新(以秒为单位。
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;
你的 setinterval 函数不应该像那样引用countDown
。试试setInterval(countDown, 60000)
.
相关文章:
- 如何在窗体打开时从javascript倒计时计时器值中节省时间
- Javascript倒计时计时器倒计时未正确更新秒/分钟
- 如何制作倒计时计时器并在时间到时更新MySQL记录
- 我怎么能有一个实时计时器,在3秒的循环内每秒钟更新一次
- asp.net实时倒计时计时器
- React计时器挂起:00(状态未更新)
- 更新网页上的计时器,并保持经过的时间--如何处理
- jQuery选择器是快照还是实时更新
- 为什么不't我的网页用JavaScript更新计时器
- 需要倒计时计时器来显示图片而不是文字,并不断更新它们
- 是否可以更新功能中的间隔计时器
- 我的计时器赢了't更新
- Ajax请求计时器更新间隔
- javascript的实时表单倒计时计时器
- 我怎样才能让这个计时器实时更新(Javascript)
- 便士拍卖计时器更新后,数据库获取
- wamp上的实时计时器
- 我怎么做,当计时器计数回来,它将刷新/更新文本文件中的文本
- 计时器倒计时为零时更新数据库
- javascript计时器在我将其更新到数据库时重置