-2

我的 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>

选中表行上的“iChecked”复选框时,应禁用文本框“Notes”。

4

2 回答 2

2

如果您使用的是 jQuery:

$(function() {
    $('#scDetails tbody input[type="checkbox"]').click(function() {
        var notes = $(this).closest('tr .notes');
        notes.prop('disabled', $(this).is(':checked'));
    });
});

只需为您的文本框提供notes类名,以便之前的选择器正常工作:

<td>@Html.TextBoxFor(m => fback.Notes, new { @class = "notes" })</td>

备注:.prop()我的示例中使用的函数是在文本框上设置禁用或只读等属性的推荐方法。它从 jQuery 1.6 开始可用。如果您使用的是旧版本的 jQuery,您可以使用该.attr()方法。

于 2012-09-25T11:18:21.837 回答
0
<script language="javascript">
<!--    
function fnDisabled(trecval)
    {
        if(trecval=="2")
        {
            document.getElementById('inputname').disabled=true;
        }
    }
</script>
于 2012-09-25T11:14:54.073 回答