我无法禁用带复选框的文本框

时间:2015-03-07 15:46:19

标签: javascript jquery onchange

我正在尝试在复选框Change事件发生时禁用/启用txtPeriodTo控件,但它似乎不起作用。我使用jquery 1.10.4,禁用文本框的prop和attr方法都不起作用。

<div id="dvWrapper" class="dvWrapper">
    <div id="content">
        <table>
            <tbody>
                <tr>
                    <td class="tdtDescription">Role:</td>
                    <td>
                        <input type="text" id="txtRoleTitle" class="txtRoleTitle" />
                    </td>
                </tr>
                <tr>
                    <td class="tdtDescription">Company Name:</td>
                    <td>
                        <input type="text" id="txtCompanyName" class="txtCompanyName" />
                    </td>
                </tr>
                <tr>
                    <td class="tdtDescription">Company Description:</td>
                    <td>
                        <textarea id="txtCompanyDescription" class="txtCompanyDescription"></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="tdtDescription">Period From
                    </td>
                    <td>
                        <input type="text" id="txtPeriodFrom" class="txtPeriodFrom" />
                    </td>
                </tr>
                <tr>
                    <td>On-Going:</td>
                    <td>
                        <input type="checkbox" id="chkOnGoing" class="chkOnGoing" />
                    </td>
                </tr>
                <tr>
                    <td class="tdtDescription">Period To
                    </td>
                    <td>
                        <input type="text" id="txtPeriodTo" class="txtPeriodTo" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>


$('.chkOnGoing').change(function () {
    var txtPeriodTo = $('.txtPeriodTo');
    if (this.checked) {
        txtPeriodTo.prop('disbaled', true);
    } else {
        txtPeriodTo.prop('disbaled', false);
    }
});

1 个答案:

答案 0 :(得分:1)

disbaled替换为disabled

$('.chkOnGoing').change(function () {
    var txtPeriodTo = $('.txtPeriodTo');
    if (this.checked) {
        txtPeriodTo.prop('disabled', true);
    } else {
        txtPeriodTo.prop('disabled', false);
    }
});