gpt4 book ai didi

javascript - 定时器Javascript

转载 作者:行者123 更新时间:2023-11-29 18:27:43 25 4
gpt4 key购买 nike

这在 IE 中不起作用。永远 - 00:00:00适用于 Chrome、Firefox。为什么?我该如何解决?

function timer()
{
var now = new Date();
var enddate = new Date("07,12,2012,23:00:00");
var totalRemains = (enddate.getTime()-now.getTime());
if (totalRemains>1)
{
var RemainsSec=(parseInt(totalRemains/1000));
var RemainsFullDays=(parseInt(RemainsSec/(24*60*60)));
var secInLastDay=RemainsSec-RemainsFullDays*24*3600;
var RemainsFullHours=(parseInt(secInLastDay/3600));
if (RemainsFullHours<10){RemainsFullHours="0"+RemainsFullHours};
var secInLastHour=secInLastDay-RemainsFullHours*3600;
var RemainsMinutes=(parseInt(secInLastHour/60));
if (RemainsMinutes<10){RemainsMinutes="0"+RemainsMinutes};
var lastSec=secInLastHour-RemainsMinutes*60;
if (lastSec<10){lastSec="0"+lastSec};
var mcend = Date.parse("Jan 1, 2009, 00:00:00");
var mcnow = now.getTime();
var mc = ((mcend-mcnow)/10).toFixed(0).substr(8);
document.getElementById('timer').innerHTML = '<p class="timeline">TIME LEFT: '+ RemainsFullHours+":"+RemainsMinutes+":"+lastSec+'</p>';
setTimeout("timer()",10);
}
else {document.getElementById("timer").innerHTML = '<p class="timeline">TIME LEFT: 00:00:00</p>';}
}

<body onload="timer();">

你能帮帮我吗?

最佳答案

问题出在这一行:

var enddate = new Date("07,12,2012,23:00:00");

这不是日期格式。 Firefox 正在英勇地理解它,不要指望 Internet Explorer 也能帮助你,IE 是无情的,他独自行走。

Date 对象构造函数有几个参数:

new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, month, day [, hour, minute, second, millisecond ])

使用dateString 选项时,您的日期字符串必须符合the RFC 2822 specification ;如果您使用受支持的格式,它会起作用:

var enddate = new Date("July 12, 2012 23:00:00");

并且,从不,从不,从不将字符串传递给 setTimeout,而是将其传递给函数引用:

setTimeout(timer,10);

在这里试试:http://jsfiddle.net/bVCMe/

文档

关于javascript - 定时器Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11457079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com