我使用Calender插件分別從&到兩個日期選擇。我需要比較value的值,並始終大於使用jQuery的值,只要我選擇日期。使用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/
檢查現有的副本。 http://stackoverflow.com/questions/658522/age-from-date-of-birth-using-jquery – Teja 2012-03-07 05:15:16
我用我的情況下,純JS它 – neoascetic 2012-03-07 05:15:23
IF((新的日期(FROM日期).getTime ()> new Date(toDate).getTime())) – Ghostman 2012-03-07 05:16:57