【问题标题】:What is a simple jquery way to select a radio when checkbox is checked and then deselect the radio when checkbox unchecked?选中复选框时选择收音机然后取消选中复选框时取消选择收音机的简单jquery方法是什么?
【发布时间】:2010-11-19 03:41:28
【问题描述】:
<input id="myCheckbox" type="checkbox" /> Please, please check me
<input id="myRadio" type="radio" /> Am I selected ?
我想要以下行为:
- 当 myCheckbox 被选中时,myRadio 将被选中。
- 当 myCheckbox 未选中时,myRadio 将变为未选中状态。
我将如何以非常简单的方式做到这一点?
提前感谢您的回复。
【问题讨论】:
标签:
jquery
checkbox
triggers
radio-button
checked
【解决方案1】:
$('#myCheckbox').click(function() {
if ($(this).is(':checked')) {
$('#myRadio').attr('checked', 'checked');
} else {
$('#myRadio').removeAttr('checked');
}
});