我迫切需要爲兩個日期生成範圍日期選擇器:開始日期和結束日期。 現在開始日期不能在日期時間之前,並且結束日期不能在選定的開始日期之前。 這裏是我想要的一個例子。可以有人告訴我用什麼來做到這一點?日期範圍的特殊日期選擇器
http://rezervari.hotelalpin.ro/
這是我試過,但沒有工作:
</head>
@using (Html.BeginForm("SearchFree", "Reservation", FormMethod.Get,new {id = "form" }))
{
<h7>Introduceti perioada Rezervarii</h7>
<div class="editor-label">
<label id="cautare" for="StartDate">Data Intrare: </label>@(Html.JQueryUI().Datepicker("StartDate").DateFormat("mm-dd-yy").MinDate(DateTime.Today).ShowButtonPanel(true).ChangeYear(true).ChangeMonth(true).NumberOfMonths(2))
</div>
<div class="editor-label">
<label id="cautare" for="EndDate">Data Iesire: </label>@(Html.JQueryUI().Datepicker("EndDate").DateFormat("mm-dd-yy").MinDate(DateTime.Today).ShowButtonPanel(true).ChangeYear(true).ChangeMonth(true).NumberOfMonths(2))
</div>
<p>
<input id="buton1" type="submit" value="Cauta camere libere" />
</p>
}
<script type="text/javascript">
$(document).ready(function() {
$.validator.addMethod("EndDate", function (value, element) {
var startDate = $('.StartDate').val();
return Date.parse(startDate) <= Date.parse(value);
}
, "* End date must be after start date");
$('.form').validate();
});
</script>
你甚至試圖找到一個? –
請參閱[此問題](http://stackoverflow.com/questions/3761185/jquery-validate-date-range)瞭解如何使用jQuery驗證的提示。 – Blazemonger
@Blazemonger你鏈接到的問題與此不同,因爲這個問題涉及2個輸入的開始和結束日期,但鏈接的問題涉及具有任意日期範圍約束的單個輸入。 – xiankai