2014-11-04 66 views
-2

我有兩個字段類似HolidayDate使得下面,如何使汽車擇日而採摘日期

[Required] 
[DataType(DataType.Date)] 
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] 
[DisplayName(Constants.DisplayName.HolidayDate)] 
    public virtual DateTime HolidayDate { get; set; } 

[StringLength(50)] 
[DisplayName(Constants.DisplayName.HolidayDay)] 
public virtual string HolidayDay { get; set; } 

在我CSHTML文件

<div class="col-md-3"> 
    <label for="" class="control-label">Date</label> 
    <br /> 
    @Html.EditorFor(model => model.HolidayDate, new { @class = "form-control"}) 
    .DisableIf(() => Model.IsReadOnly == true) 
</div> 
<div class="col-md-3"> 
    <label for="" class="control-label">Day</label> 
    <br /> 
    @Html.TextBoxFor(model => model.HolidayDay, new { @class = "form-control"}) 
    .DisableIf(() => Model.IsReadOnly == true) 
</div> 

如果我選擇一個日期HolidayDate字段,那麼該日期的那一天應該自動在HolidayDay字段中指定,所以請任何人都可以幫助找到解決方案

+0

顯示jQuery代碼 – 2014-11-04 04:57:45

+0

$(文件)。就緒(函數(){ $(「# HolidayDate「)。datepicker( { altField:」#HolidayDay「, altFormat:」DD「 }); }); – 2014-11-04 05:25:55

+0

請參閱編輯的代碼.....如果你能幫助,那麼請幫我 – 2014-11-04 05:32:16

回答

0

嘗試

$('#HolidayDate').change(function() { 
    var date = new Date($(this).val()); 
    $('#HolidayDay').val(date.getDate()); 
}); 

,或者如果你想顯示星期幾

var daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] 
$('#HolidayDate').change(function() { 
    var date = new Date($(this).val()); 
    $('#HolidayDay').val(daysOfWeek[d.getDay()]); 
}); 

Refer fiddle

+0

JQuery不工作,我的意思是這個功能不叫 – 2014-11-04 06:24:29

+0

適合我。你有任何瀏覽器錯誤?包括jquery。腳本在頁面底部嗎?可能是任何數量的問題 - 調試它! – 2014-11-04 06:28:11

+0

可以給我發送完整的密碼,我的意思是從

相關問題