【发布时间】:2012-03-07 05:11:39
【问题描述】:
我正在使用 Calender 插件分别从 & to 选择两个日期。选择日期后,我需要比较 的值 总是大于使用 jQuery 的值。
我正在使用以下代码
var fromDate = $("#from").val();
var toDate = $("#to").val();
if (Date.parse(fromDate) > Date.parse(toDate)) {
alert("Invalid Date Range!\nStart Date cannot be after End Date!")
return false;
}
HTML代码是:
<input type="text" name="from" id="from" value="" class="datepicker validate[custom[date]]" tabindex="4" />
<input type="text" name="from" id="from" value="" class="datepicker validate[custom[date]]" tabindex="4" />
如果我使用 jquery 验证插件进行比较:
<input value="" class="validate[required,custom[date],future[2009-01-01]" type="text" id="d1" name="d1" />
如http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
【问题讨论】:
-
检查现有的副本。 stackoverflow.com/questions/658522/…
-
我在我的情况下使用纯 JS
-
if( (new Date(fromDate).getTime() > new Date(toDate).getTime()))
-
有什么问题?你有任何错误吗?
标签: jquery validation date