admin管理员组文章数量:1391747
I am using jQuery. How to enable or disable textbox inside a table when checkbox checked. This is my 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>
What i have tried is:
$('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);
}
});
Where am doing wrong? I dont want to use any classes on the controls to achieve this.
I am using jQuery. How to enable or disable textbox inside a table when checkbox checked. This is my 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>
What i have tried is:
$('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);
}
});
Where am doing wrong? I dont want to use any classes on the controls to achieve this.
Share Improve this question edited Sep 26, 2012 at 2:19 Eli 14.8k5 gold badges61 silver badges77 bronze badges asked Sep 26, 2012 at 2:08 user1282609user1282609 5752 gold badges14 silver badges32 bronze badges1 Answer
Reset to default 8You missed the quotes, and you could simply your code with:
$('td input[type="checkbox"]').change(function () {
$(this).closest('tr').find('input[type="text"]').prop('disabled', !this.checked);
}).change();
本文标签: javascriptenable disable textbox inside a table when checkbox checkedStack Overflow
版权声明:本文标题:javascript - enable disable textbox inside a table when checkbox checked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744772380a2624416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论