Jquery 如果被其他收音机禁用,如何取消选中单个单选按钮?

Jquery 如果被其他收音机禁用,如何取消选中单个单选按钮?,jquery,radio,Jquery,Radio,jQuery新手,这里。我不能让它工作。这是我用来禁用一个单选按钮基于以前的单选按钮 $('document').ready(function() { $('input[name="a"]').change(function() { if($(this).val() == '1') { $('input[name="b"]').removeAttr('disabled'); } else { $('input

jQuery新手,这里。我不能让它工作。这是我用来禁用一个单选按钮基于以前的单选按钮

$('document').ready(function() {
    $('input[name="a"]').change(function() {
        if($(this).val() == '1') {
            $('input[name="b"]').removeAttr('disabled');
        } else {
            $('input[name="b"][value="1"]').attr('disabled','disabled');
        }
    });
});
以及:

它完成了任务,但如果我先检查B-2,它也会取消选中。我只希望B-1不被检查。(我希望这是有道理的。)


我做错了什么?

过去我必须很快学会这样的东西:诀窍是制作一系列单选按钮:

family NAME
  child ID0
  child ID1
  child IDn
在您的特定情况下,您可能正在寻找类似的东西(性别):

此外,您还可以通过单击以下命令来启动其中任何一个:$(“#男性”)。单击()

这是你想要的

[value=“1”]选择器thou(在未选中的情况下使用)有一个问题,闻起来像jquery bug。但别担心;)


和^^

如果选择了另一个单选按钮,您是否始终希望取消选择以前选中的单选按钮?
if($('input[name="b"][value="1"]').is(':disabled')) {
    $('input[name="b"][value="1"]').removeAttr('checked');
}
family NAME
  child ID0
  child ID1
  child IDn
<input type="radio" name="gender" id='male' value="M" > Male
<input type="radio" name="gender" id='female' value"F" > Female
<input type="radio" name="likes" id='tv' value="TV" > Watchs TV
<input type="radio" name="likes" id='radio' value="radio" > Listens to Radio
$('#male').is(':checked') .... $('#female').is(':checked') .....
$('input[name="a"]').change(function () {
    var $b = $('input[name="b"]');
    if (this.value == 1) {
        $b.removeAttr('disabled');
    }
    else {
        $('input[name="b"][value="1"]:checked').removeAttr('checked');  // the selector behavior is funky here...
        $b.attr('disabled', true);
    }
});