【问题标题】: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 ?

我想要以下行为:

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

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

提前感谢您的回复。

【问题讨论】:

    标签: jquery checkbox triggers radio-button checked


    【解决方案1】:
    $('#myCheckbox').click(function() {
        if ($(this).is(':checked')) {
            $('#myRadio').attr('checked', 'checked');
        } else {
            $('#myRadio').removeAttr('checked');
        }
    });
    

    【讨论】:

    • 哇。那很快。谢谢!
    猜你喜欢
    • 2015-05-19
    • 2012-10-16
    • 2016-09-24
    • 1970-01-01
    • 2013-09-29
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    相关资源
    最近更新 更多