javascript - IE 和 Firefox 中的 NaN 字符

标签 javascript return nan

这是我的 HTML 代码:

<ul class="countdown">
  <li class="timer"><div  id="days"></div><H1>Days</H1></li>
  <li class="timer"><div  id="hours"></div><H1>Hours</H1></li>
  <li class="timer"><div  id="mins"></div><H1>Minutes</H1></li>
  <li class="timer"><div  id="secs"></div><H1>Seconds</H1></li>
</ul>

这是 JS 代码,

var xmas = new Date("jule 2, 2014 00:01:00");
var now = new Date();
var timeDiff = xmas.getTime() - now.getTime();
if (timeDiff <= 0) {
    clearTimeout(timer);
    document.write("Christmas is here!");
    // Run any code needed for countdown completion here
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("mins").innerHTML = minutes;
document.getElementById("secs").innerHTML = seconds;
var timer = setTimeout('cdtd()',1000);

结果在 Chrome 中工作,但 IE 和 Firefox 返回 NaN

最佳答案

我成功了。

现场示例:http://testnaman.neocities.org/quicktest2.html 。这不会是永久性的。

您需要更改:

var xmas = new Date("jule 2, 2014 00:01:00");

致:

var xmas = new Date("July 2, 2014 00:01:00");

看来 Firefox 不喜欢错误的拼写。

有关更多信息,请查看:new Date() is working in Chrome but not Firefox .

关于javascript - IE 和 Firefox 中的 NaN 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23845576/

相关文章:

powershell - powershell函数返回用户定义类的实例将导致构造函数返回另一个新实例

python - 将列数据框与另一个数据框映射

python - 比较包含 NaN 的 numpy 数组

javascript - 使用 Node js从时区获取时间

javascript - 为什么人们在 render() 中从 React 中的状态属性定义变量?

ruby - 使 Ruby 循环返回 "x"图像而不是整数 x

java - 如何使方法打印出特定数字的滚动次数?

javascript - 具有用户输入的数组上的 NaN

javascript - 在 Durandal 框架中使用 Typeahead 创建自动完成字段

php - Facebook OAuth 和 PHP SDK...错误