这在IE和Edge上运行良好,但在Chrome和Firefox中显示NaN:NaN。请提供理由和正确的解决方案 我试图只显示一个小时的减少时间。
<!--HERE IS MY CODE-->
<!--THE CODE CREATIN ERROR-->
<html>
<head>
<script>
endtime="31/12/2015";
var myvar=setInterval(myfunc,1000);//function calling after every 1 second
var d=new Date();
d.setHours(14);
d.setMinutes(00);
k=00;
j=01;
function myfunc()
{strong text
d.setSeconds(k);
k++;
if(k==60)
{
d.setMinutes(j);
k=00;
j++;
}
var t = parseFloat(Date.parse(endtime) - Date.parse(d));
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
document.getElementById("div1").innerHTML=minutes.toString()+":"+seconds.toString();/*HERE IT IS SAYING NAN:NAN IN CHROME AND FIREFOX*/
}
</script>
</head>
<body>
<p id="demo"></p>
<div id="div1"></div>
</body>
</html>
答案 0 :(得分:0)
尝试用新方法解决问题并完成它。
<html>
<head>
<script>
var t = parseFloat(3600000);
var myvar=setInterval(myfunc,1000);
function myfunc()
{
if(t>0)
{
var seconds = parseFloat(Math.floor( (t/1000) % 60 ).toString());
var minutes = parseFloat(Math.floor( (t/1000/60) % 60 ).toString());
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
document.getElementById("div1").innerHTML=minutes+":"+seconds;
t=t-1000;
};}
</script>
</head>
<body>
<p id="demo"></p>
<div id="div1"></div>
</body>
</html>