【发布时间】:2010-12-20 06:54:44
【问题描述】:
我希望选中/取消选中一个复选框并让它启用/禁用提交按钮。 Javascript 触发,不显示错误,但提交输入不会多次切换。
JS:
$('#readTerms').change(function() {
var buttonsChecked = $('#readTerms:checked');
if (buttonsChecked.length)
{
$('#submitBusiness').removeAttr('disabled');
}
else
{
$('#submitBusiness').attr('disabled', 'disabled');
}
});
HTML:
<input type="checkbox" id="readTerms" name="agree"> <label for="agree">By checking the box you agree to the <a href="/terms" target="_blank">Terms & Conditions</a>.</label>
<input id="submitBusiness" class="btn positive iconCheck right" type="submit" name="create" value="Submit" disabled="disabled" />
提交按钮开始禁用。单击复选框,它启用,再次单击复选框,没有。 if/else 语句工作正常。代码会触发,它会触发 firebug 等中的断点,等等等等。
我做错了什么?
【问题讨论】:
-
为我工作;什么浏览器,jquery版本?试试
attr('disabled',true)