小编Dak*_*ota的帖子

选中复选框时,jQuery禁用表单元素

我有一个复杂的jQuery表单,如果选中某个复选框,我想禁用几个表单元素.我正在使用jQuery 1.3.2,以及所有相关的插件.我在这做错了什么?谢谢,达科他州

这是我的HTML:

    <li id="form-item-15" class="form-item">
        <div class='element-container'>
            <select id="house_year_built" name="house_year_built" class="form-select" >
                 ...Bunch of options...
            </select>
            <input type="text" title="Original Purchase Price" id="house_purchase_price" name="house_purchase_price" class="form-text money" />
            <input type="text" title="Current Home Debt" id="house_current_debt" name="house_current_debt" class="form-text money" />
        </div>
        <span class="element-toggle">
            <input type="checkbox" id="house_toggle" />
            <span>Do not own house</span>
        </span>
    </li>
Run Code Online (Sandbox Code Playgroud)

这是我的jQuery:

$('.element-toggle input').change(function () { 
    if ($(this).is(':checked')) $(this).parents('div.element-container').children('input,select').attr('disabled', true);
    else $(this).parents('div.element-container').children('input,select').removeAttr('disabled'); }); 
Run Code Online (Sandbox Code Playgroud)

forms checkbox jquery javascript-events

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

checkbox ×1

forms ×1

javascript-events ×1

jquery ×1