在jQuery中单击复选框时如何启用按钮? [英] How to enable button when checkbox clicked in jQuery?

查看:113
本文介绍了在jQuery中单击复选框时如何启用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery中单击复选框时如何启用按钮?

How to enable button when checkbox clicked in jQuery?

推荐答案

您可以这样做:

$("#checkBoxID").click(function() {
  $("#buttonID").attr("disabled", !this.checked);
});

此选项在选中时启用,并且在取消选中时再次禁用.在jQuery中,.attr("disabled", bool)需要一个布尔值,因此您可以使用复选框的this.checked DOM属性使之保持简短.

This enables when checked, and disables again if you uncheck. In jQuery .attr("disabled", bool) takes a boolean, so you can keep this pretty short using the this.checked DOM property of the checkbox.

这篇关于在jQuery中单击复选框时如何启用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆