简体   繁体   English

选择单选按钮后将复选框设置为选中状态

[英]Set checkbox as checked after radio button selection

For the beginning, I've Form that includes:一开始,我的表格包括:

  • Three radio button (id: a-option,b-option,c-opion),三个单选按钮(id:a-option,b-option,c-opion),
  • One Checkbox (id: optional),一个复选框(id:可选),

and i would like to achieve that Checkbox can be selected manually as usual, but also the two of them should mark checkbox as selected automatically and disable possibility of unchecking it (let's say that will be b-option and c-option).我想实现可以像往常一样手动选择复选框,但他们两个应该将复选框标记为自动选中并禁用取消选中它的可能性(假设将是 b-option 和 c-option)。 How should i do that with JS or JQuery.我应该如何使用 JS 或 JQuery 来做到这一点。

You can trigger checked property to #optional on click:您可以在单击时将checked的属性触发为#optional

$('#c-option').click(function(){
   $('#optional').prop('checked', true);
   $('#optional').prop('disabled', true);
});

$('#b-option').click(function(){
   $('#optional').prop('checked', true);
   $('#optional').prop('disabled', true);
});

$('#a-option').click(function(){
   $('#optional').prop('checked', false);
   $('#optional').prop('disabled', false);
});

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

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