4
<input id="myCheckbox" type="checkbox" /> Please, please check me
    <input id="myRadio" type="radio" /> Am I selected ?

我想要以下行为:

  1. 当 myCheckbox 被选中时,myRadio 将被选中。
  2. 当 myCheckbox 未选中时,myRadio 将变为未选中状态。

我将如何以非常简单的方式做到这一点?

预先感谢您的回复。

4

1 回答 1

9
$('#myCheckbox').click(function() {
    if ($(this).is(':checked')) {
        $('#myRadio').attr('checked', 'checked');
    } else {
        $('#myRadio').removeAttr('checked');
    }
});
于 2009-08-13T00:00:41.157 回答