[英]enable disable textbox inside a table when checkbox checked
我正在使用jQuery。 選中復選框時,如何在表內啟用或禁用文本框。 這是我的edit.cshtml。
<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.DisplayFor(m => fback.RItem)</td>
<td>@Html.CheckBoxFor(m => fback.IChecked)</td>
<td>@Html.TextBoxFor(m => fback.Notes)</td>
</tr>
}
</tbody>
</table>
我試過的是:
$('td :checkbox').change(function () {
var parentTx = $(this).closest('tr').find(input[type = "text"]);
if (this.checked) {
parentTx.attr("disabled",false);
} else {
parentTx.attr("disabled", true);
}
});
哪里做錯了? 我不想在控件上使用任何類來實現這一點。
你錯過了報價,你可以簡單地用你的代碼:
$('td input[type="checkbox"]').change(function () {
$(this).closest('tr').find('input[type="text"]').prop('disabled', !this.checked);
}).change();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.