简体   繁体   English

我如何在单击另一个单选按钮时禁用单选按钮

[英]how can i disable a radio button on click to another radio button

how can i disable and enable a sub radio button on click to the another radio button using jquery. 我如何禁用和启用子单选按钮单击到另一个单选按钮使用jQuery。

I want to disable radio button(er_que) when i click radio button(#atten) and enable the same when i click radio button(#quest) 我想在单击单选按钮(#atten)时禁用单选按钮(er_que),并在单击单选按钮(#quest)时启用单选按钮

<tr>
      <td>What do you want to know?<br />
         <input name="er_1" id="atten" type="radio" value="attendence" /> Attendance<br />
         <input name="er_1" id="quest" type="radio" value="que_ask" /> Questions Asked<br />
       </td>
</tr>
<tr>
   <td><input name="er_que" type="radio" value="total" /> Total Number<br />
       <input name="er_que"  type="radio" value="issue_wise" /> Issues Wise
</td>
$('input[name="er_1"]').change(function() {
    if ($(this).val() == 'attendence') {
        $('input[name="er_que"]').attr('disabled', 'disabled');
         return;
    } 

    $('input[name="er_que"]').removeAttr('disabled');              
}
});

Something like this: 像这样:

$('document').ready(function() {
    $('input[name="er_1"]').change(function() {
        if ($(this).val() == 'attendence') {
            $('input[name="er_que"]').removeAttr('disabled');
        } else {
            $('input[name="er_que"]').attr('disabled', 'disabled');
        }
    });
});

Working demo: 工作演示:

http://jsfiddle.net/eH55n/ http://jsfiddle.net/eH55n/

The following should do the trick: 以下应该可以解决问题:

// Disable //
$('#atten').click(function(){
    $('input[name="eq_que"]').attr('disabled','disabled');
});

// Enable //
$('#quest').click(function(){
    $('input[name="eq_que"]').removeAttr("disabled");
});

I hope it helps! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM