为了账号安全,请及时绑定邮箱和手机立即绑定

单击另一组复选框中的选项时,一组复选框中的选项必须保留为默认值

单击另一组复选框中的选项时,一组复选框中的选项必须保留为默认值

米脂 2021-06-29 09:31:56
我有两组复选框。当我选择带有 id radio14 的复选框(在第一个中)时,我希望自动选中带有 id radio12 的复选框作为默认值。var chk1 = document.getElementById("#radio14");var chk2 = document.getElementById("#radio12");chk1.onclick = function(){  if( chk1.checked == 1 ) {    chk2.setAttribute('checked', true);  } else {    chk2.setAttribute('checked', false);  }};<input type="radio" name="Finishing" id="radio12" class="radio"/><label for="radio12">Silky Matt lamination</label><input type="radio" name="Special_Finishing" id="radio14" class="radio"/> <label for="radio14">Digital Embossing </label>
查看完整描述

1 回答

?
德玛西亚99

TA贡献1770条经验 获得超3个赞

试试这个:


const checkbox1 = document.getElementById('radio14');

const checkbox2 = document.getElementById('radio12');


checkbox1.addEventListener('change', () => {

  if (checkbox1.checked) {

    checkbox2.setAttribute('checked', true);

  } else {

    checkbox2.setAttribute('checked', false);

  }

});

<input type="radio" id="radio12" />

<label for="radio12">Silky Matt lamination</label>


<input type="radio" id="radio14"/> 

<label for="radio14">Digital Embossing</label>

如果您正在使用getElementById,则只需通过id,无需#.


查看完整回答
反对 回复 2021-07-08
  • 1 回答
  • 0 关注
  • 153 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信