如何使用 jQuery 使一组单选按钮处于非活动状态?

发布于 2024-08-17 06:14:37 字数 147 浏览 2 评论 0原文

我想要一组单选按钮,它们在单击复选框之前处于非活动状态。

换句话说,当用户选中复选框时,它将允许用户使用单选按钮。如果用户取消选中复选框,则单选按钮将处于非活动状态,因此用户无法再选择它们。

有没有使用 jQuery 的解决方案可以用来实现此目的?

I want to have a group of radiobuttons that are inactive until a checkbox is clicked.

In other words, when the user checks a checkbox, it will allow the user to use the radiobuttons. If the user unchecks a checkbox, it will make the radiobuttons inactive, so the user cannot select them anymore.

Is there a solution using jQuery that I can use to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2024-08-24 06:14:37

假设单选按钮都具有相同的名称,那么您可以使用 属性选择器 this:

$('#checkboxid').click(function() {
    $('input[name="radiobuttonname"]').attr('disabled', !this.checked);
});

如果选中该复选框,这将启用单选按钮;如果未选中,则禁用单选按钮。

Assuming that the radiobuttons have all the same name, then you can use the attribute selector for this:

$('#checkboxid').click(function() {
    $('input[name="radiobuttonname"]').attr('disabled', !this.checked);
});

This will enable the radiobuttons if the checkbox is checked and disable when unchecked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文