选中复选框后,启用表内的禁用文本框

use*_*609 3 javascript jquery

我正在使用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>
Run Code Online (Sandbox Code Playgroud)

我试过的是:

 $('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);
            }
        });
Run Code Online (Sandbox Code Playgroud)

哪里做错了?我不想在控件上使用任何类来实现这一点.

xda*_*azz 7

你错过了报价,你可以简单地用你的代码:

$('td input[type="checkbox"]').change(function () {
  $(this).closest('tr').find('input[type="text"]').prop('disabled', !this.checked);
}).change();
Run Code Online (Sandbox Code Playgroud)