私の MVC アプリケーションでは、日付フィールドを必要とするすべての入力ボックスに datepicker クラスを割り当てることができます。以前は、次のプロパティを使用して datepicker を設定できました (機能していました)。
$(".datePicker").datepicker({
showOn: 'both',
dateFormat: 'dd MM yy',
changeMonth: true,
changeYear: true,
yearRange: 'c-1:c+1',
beforeShowDay: noWeekendsOrHolidays });
ここで、別の設定が必要な生年月日日付ピッカーを割り当てる必要があります。したがって、その要素については、次のように要素をラップします。
<span class="allDates"><%: Html.EditorFor(model => model.Employee.Dob)%></span>
したがって、ビューがレンダリングされると、ビュー ソースからの Html は次のようになります。
<tr>
<td style="text-align: right;">
<label for="Employee_Dob">Date of Birth</label>
</td>
<td colspan="2">
<span class="allDates">
<input class="datePicker" id="Employee_Dob" name="Employee.Dob" type="text" value="" />
</span>
</td>
</tr>
今私のjqueryは動作しません - これは誰かにとって簡単な修正だと思います。
$(function () {
$(".datepicker").each(function() {
if ($(this).parent().hasClass("allDates")) {
$(this).datepicker({ showOn: 'both', dateFormat: 'dd MM yy', changeMonth: true, changeYear: true, yearRange: 'c-100:c' });
} else {
$(this).datepicker({ showOn: 'both', dateFormat: 'dd MM yy', changeMonth: true, changeYear: true, yearRange: 'c-1:c+1', beforeShowDay: noWeekendsOrHolidays });
}
});
});