Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选中复选框时启用或禁用td内的文本框_Jquery_Asp.net Mvc - Fatal编程技术网

Jquery 选中复选框时启用或禁用td内的文本框

Jquery 选中复选框时启用或禁用td内的文本框,jquery,asp.net-mvc,Jquery,Asp.net Mvc,My Edit.cshtml- <table id="scDetails" class="dataTable"> <thead> <tr> <th>RItem</th> <th>IChecked</th> <th>Notes</th>

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.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>

仪式
艾切克
笔记
@foreach(Model.Fbacks中的var fback)
{
@Html.HiddenFor(m=>fback.FItem)
@DisplayFor(m=>fback.RItem)
@CheckBoxFor(m=>fback.IChecked)
@Html.TextBoxFor(m=>fback.Notes)
}
当选中表格行上的复选框“IChecked”时,应启用文本框“Notes”,否则将被禁用。


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

如果您使用的是jQuery:

$(function() {
    $('#scDetails tbody input[type="checkbox"]').click(function() {
        var notes = $(this).closest('tr .notes');
        notes.prop('disabled', $(this).is(':checked'));
    });
});
只需在文本框中输入
注释
类名,即可使前面的选择器正常工作:

<td>@Html.TextBoxFor(m => fback.Notes, new { @class = "notes" })</td>
@Html.TextBoxFor(m=>fback.Notes,new{@class=“Notes”})
备注:我的示例中使用的函数是在文本框上设置属性(如disabled或readonly)的推荐方法。它可以从jQuery 1.6开始使用。如果您使用的是较旧版本的jQuery,则可以使用该方法。

我尝试过使用此方法$(“输入[type=checkbox][id*=IsChecked]”。单击(函数(){if(this.checked)$(this.closest)(“tr”).find(“输入[type=text][id*=Notes]”)。attr(“禁用”,false);