2012-09-25 202 views
-2

我Edit.cshtml -啓用或內TD禁用文本框時,選中複選框

<table id="scDetails" class="dataTable"> 
     <thead> 
      <tr> 
       <th>RItem</th> 
       <th>IChecked</th> 
       <th>Notes</th> 
      </tr> 
     </thead> 
     <tbody> 
      @foreach (var fback in Model.Fbacks) 
      { 
       <tr> 
        <td>@Html.HiddenFor(m => fback.FItem) 

         @Html.DisplayFor(m => fback.RItem) 
        </td> 
        <td>@Html.CheckBoxFor(m => fback.IChecked)</td> 
        <td>@Html.TextBoxFor(m => fback.Notes)</td> 
       </tr> 
      } 
     </tbody> 
    </table> 

當錶行複選框「IChecked」被選中,文本框「注意事項」應啓用,否則禁用。

+0

我試過用這個。 $(「input [type = checkbox] [id * = IsChecked]」)。click(function(){if(this.checked) $(this).closest(「tr」)。find(「input [type = text] [id * = Notes]「)。attr(」disabled「,false); – user1282609

回答

2

如果您正在使用jQuery:

$(function() { 
    $('#scDetails tbody input[type="checkbox"]').click(function() { 
     var notes = $(this).closest('tr .notes'); 
     notes.prop('disabled', $(this).is(':checked')); 
    }); 
}); 

只要給你的文本框中notes類名,這樣前面的選擇正常工作:

<td>@Html.TextBoxFor(m => fback.Notes, new { @class = "notes" })</td> 

備註:所使用的.prop()功能我示例是在文本框上設置屬性(如禁用或只讀)的推薦方法。它可以從jQuery 1.6開始。如果您使用的是舊版本的jQuery,則可以使用.attr()方法。

0
<script language="javascript"> 
<!--  
function fnDisabled(trecval) 
    { 
     if(trecval=="2") 
     { 
      document.getElementById('inputname').disabled=true; 
     } 
    } 
</script> 
相關問題