有人知道为什么在Firefox中执行以下代码,如果传入的字符串是四个数字且仅为四个数字,则它将将其验证为日期吗?在我测试的所有其他浏览器(IE,Chrome)中,它始终返回不是日期。
由于规范,如Marcel Korpel所指出的那样,指出它应该回退到使用Firefox的特定于实现的回退,因此我真的想知道为什么Firefox的回退会显示这种异常情况。
function isDate(sDate) {
var temp = new Date(sDate);
if (temp.toString() == "NaN" || temp.toString() == "Invalid Date") {
alert("Not a Date");
} else {
alert("Is a Date!");
}
}
toString
来测试NaN
?而不是使用isNaN(temp)
? - Marcel Korpel