如何使用 jQuery 使一组单选按钮处于非活动状态?
我想要一组单选按钮,它们在单击复选框之前处于非活动状态。
换句话说,当用户选中复选框时,它将允许用户使用单选按钮。如果用户取消选中复选框,则单选按钮将处于非活动状态,因此用户无法再选择它们。
有没有使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设单选按钮都具有相同的名称,那么您可以使用 属性选择器 this:
如果选中该复选框,这将启用单选按钮;如果未选中,则禁用单选按钮。
Assuming that the radiobuttons have all the same name, then you can use the attribute selector for this:
This will enable the radiobuttons if the checkbox is checked and disable when unchecked.