[英]enable textbox when checkbox checked in a TABLE ROW
我的submit.cshtml
是:
<table id="scDetails" class="table">
<thead>
<tr>
<th>Item</th>
<th>IsChecked</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
@Html.EditorFor(m => m.Fbacks)
</tbody>
</table>
EditorTemplate適用於- @Html.EditorFor(m => m.Fbacks)
(Fbacks.cshtml)
<tr>
<td>@Html.HiddenFor(m => m.Item)
@Html.DisplayFor(m => m.Item)
</td>
<td>@Html.CheckBoxFor(m => m.IsChecked)</td>
<td>@Html.TextBoxFor(m => m.Comment)</td>
</tr>
我需要的是:
當我選中復選框時,應啟用文本框,而當取消選中時,應禁用文本框。
$("input[type='checkbox']").on("click", function() {
$(this).parent().next().find("textarea").prop("disabled", ! this.checked);
});
$('input[type=checkbox]').on('click', function() {
var isChecked = $(this).is(':checked');
$(this).parent().next().find('input[type="text"]').attr('disabled', !isChecked);
});
// OR
$('input[type=checkbox]').on('click', function() {
var isChecked = $(this).is(':checked');
$(this).parent().parent().find('input[type="text"]').attr('disabled', !isChecked);
});
您應該將事件添加到復選框
$('#Fbacks').click (function ()
{
var thisCheck = $(this);
if (thischeck.is (':checked'))
{
$('#Comment').prop('disabled', true);
}else{
$('#Comment').prop('disabled', false);
}
});
在這種情況下@Html.EditorFor(m => m.Fbacks)
id = 'Fbacks'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.