0

私の 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 });
        }
    });
});
4

1 に答える 1

1

DOB フィールドに追加のクラスを指定してから、別のオプション セットを使用して日付ピッカーを再度作成します。

class="datepicker dob"

$(".datepicker.dob").datepicker('destroy').datepicker({ 
    showOn: 'both',
    dateFormat: 'dd MM yy',
    changeMonth: true,
    changeYear: true,
    yearRange: 'c-100:c'
});

または、その特定の日付ピッカーのみでオプションを再作成するには:

$("#Employee_Dob.datePicker").datepicker('destroy').datepicker({ 
    showOn: 'both',
    dateFormat: 'dd MM yy',
    changeMonth: true,
    changeYear: true,
    yearRange: 'c-100:c'
});
于 2012-12-05T10:20:04.617 に答える