由于JQuery功能,单选按钮默认选中不起作用

Har*_*pta 1 html javascript checkbox jquery radio-button

我有一个以下列方式绑定到复选框的单选按钮列表.

1)选中复选框后,单选按钮被启用并检查默认按钮(例如值= 1)(只能从三个中选择一个单选按钮)

2)取消选中该复选框时,单选按钮为禁用及其选择属性已删除.

我面临的问题是,由于以下HTML和Jquery代码,页面加载(值= 1)上的单选按钮的默认选择不起作用.我无法识别错误.有人可以帮忙吗?

$('#mailcheck').change(function() {
  $('input[name="freq"]').prop('disabled', !this.checked);
  $('input[name="freq"]').removeAttr('checked');
}).change();
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="notcheck">
  <input type="checkbox" id="mailcheck" checked="checked">I want to receive an email notification of ads uploaded on my college marketplace
</label>
<br>

<ul>
  <li>
    <label>
      <input type="radio" name="freq" value="1" id="freqradio" checked="checked">Daily</label>
  </li>
  <li>
    <label>
      <input type="radio" name="freq" value="3" id="freqradio">Every 3 days</label>
  </li>
  <li>
    <label>
      <input type="radio" name="freq" value="7" id="freqradio">Weekly</label>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

小智 5

这是一个粗略的工作版本:

$('#mailcheck').change(function(){
    if($(this).is(':checked')) {
        $('input[name="freq"]').prop('disabled', false).first().prop('checked', true);
    } else {
        $('input[name="freq"]').prop('disabled', true).prop('checked', false);
    }
})
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<label id="notcheck">
 <input type="checkbox" id="mailcheck" checked="checked" >I want to receive an email notification of ads uploaded on my college marketplace
</label><br>

  <ul>
   <li><label><input type="radio" name="freq" value="1" id="freqradio1" checked="checked">Daily</label></li>
   <li><label><input type="radio" name="freq" value="3" id="freqradio2">Every 3 days</label></li>
   <li><label><input type="radio" name="freq" value="7" id="freqradio3">Weekly</label></li>
  </ul>
Run Code Online (Sandbox Code Playgroud)

ps ids必须具有唯一值