【发布时间】:2013-09-26 15:57:21
【问题描述】:
我有一个超级简单的 jQuery 验证方法,它在出生日期字段上运行。它所做的只是检查输入的日期(来自 HTML5 输入 type=date 字段)是否早于当前日期。如果是,则有效,否则无效。它在 Chrome 中运行良好,但由于某种原因在 Safari 中失败,就像输入了无效日期一样。代码如下:
$.validator.addMethod("bornBeforeToday", function(value, element) {
// For DOB, check that value given is before the current date
if (value.length > 0) {
return Date.parse(value) < new Date();
} else {
return true;
}
}, "Date must be less than than current date");
【问题讨论】:
-
是抛出错误还是根本没有运行?
-
抛出有关不正确日期的错误,因此它正在运行但未正确验证日期。
-
尝试将返回标志设置为一个变量,并且只有 1 个返回语句。
-
Date.parse(value)返回一个类似-1775674800000的数字,但是,new Date()返回Thu Sep 26 2013 12:57:01 GMT-0500 (CST)。
标签: jquery html date safari jquery-validate