0

我與ASP.NET的MVC3.I've下表工作視圖頁面上,問題與DatePicker的變化

 <table> 
     <tr> 
     <th>Id</th> 
     <th>Name</th> 
     <th>date1</th> 
     <th>date2</th> 
     </tr> 
     @foreach(var item in Model.data) 
     { 
     <tr> 
     <td>@item.Id</td> 
     <td>@item.Name</td> 
     @if(@item.date1==""){ 
     <td><input type="text" name="date1" class="date1"></td> 
     } 
     else{ 
<td>@Html.TextBox("date1",item.date1, new { @class="date1" })</td> 
     } 
     @if(@item.date2==""){ 
     <td><input type="text" name="date2" class="date2"></td> 
     } 
      else{ 
<td>@Html.TextBox("date2",item.date2, new { @class="date2" })</td> 
     } 
       </tr> 
     } 
     </table> 

以下是我使用該日期選擇器的jQuery,

$(function() { 
    $(".date1").datepicker({ 
     dateFormat: 'dd/M/yy' 
    }); 
    $(".date2").datepicker({ 
     dateFormat: 'dd/M/yy' 
    }); 
}); 

第一次當我選擇第一行的日期時,所選的日期在正確的文本框中更新。但是當我更改第二行的現有日期值時,日期更改發生在第一行文本框中。

+0

你有被操縱這些值一些其他的JavaScript代碼? – dotnetom

+0

請在jsfiddle中添加演示也 –

+0

請找到更新的代碼 – user2514925

回答

0

試試這個:

<table> 
      <tr> 
      <th>Id</th> 
      <th>Name</th> 
      <th>date1</th> 
      <th>date2</th> 
      </tr> 
      @foreach(var item in Model.data) 
      { 
      <tr> 
      <td>@item.Id</td> 
      <td>@item.Name</td> 
      <td><input type="text" id="date1" name="date1" class="date1" value="@item.date1=="" ? "" : @item.date1"/></td> 
      <td><input type="text" id="date2" name="date2" class="date2" value="@item.date2=="" ? "" : @item.date2"/></td> 
      </tr> 
      } 
      </table> 

$(function() { 
    $("#date1").datepicker({ 
     dateFormat: 'dd/M/yy' 
    }); 
    $("#date2").datepicker({ 
     dateFormat: 'dd/M/yy' 
    }); 
});