什么是简单的 jquery 方法来在选中复选框时选择无线电,然后在取消选中复选框时取消选择无线电?
-
13-09-2019 - |
题
<input id="myCheckbox" type="checkbox" /> Please, please check me
<input id="myRadio" type="radio" /> Am I selected ?
我想要以下行为:
- 当 myCheckbox 被选中时, myRadio 将被选中。
- 当 myCheckbox 未被选中时, myRadio 将被取消选中。
我将如何以一种非常简单的方式做到这一点?
预先感谢您的努力回复。
解决方案
$('#myCheckbox').click(function() {
if ($(this).is(':checked')) {
$('#myRadio').attr('checked', 'checked');
} else {
$('#myRadio').removeAttr('checked');
}
});
不隶属于 StackOverflow