复选框启用/禁用提交仅一次,jquery
我希望选中/取消选中复选框并启用/禁用提交按钮。 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 中触发断点等等。
我做错了什么?
I expect to check/uncheck a checkbox and have it enable/disable a submit button. Javascript fires, doesn't show errors, but the submit input just will not toggle more than once.
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" />
Submit button starts disabled. Click the checkbox and it enables, click the checkbox again and nothing. The if/else statement works fine. The code fires, it trips breakpoints in firebug, etc. etc. etc.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试这样的事情:
I would try something like this instead:
尝试这样的事情:
示例: http://jsfiddle.net/redler/TETg6/
Try something like this:
Example: http://jsfiddle.net/redler/TETg6/