繁体   English   中英

如何通过选择特定的单选按钮组来重置多个单选按钮组

[英]How can I reset many radio button groups by selecting a specific radio button group

我在下面有三个名为“类型”的不同组。 在这些组下是具有不同名称的其他按钮组。 当我选择任何“类型”命名的单选按钮时,我想清除(重置)所有其他可能被选中的“类型”组单选按钮旁边的单选按钮。
 <input type="radio" value="three egg breakfast" name="type"> <img src="threeeggbreakfasttext.jpg" class="roundcorn"> <input type="radio" value="white toast" name="threeeggtoast"> <img src="whitetext.jpg" width="44" height="26" class="roundcorn"> <label><input type="radio" value="whole wheat toast" name="threeeggtoast"> <img src="wholewheattext.jpg" width="108" height="26" class="roundcorn"></label> <label><input type="radio" value="hash brown" name="threeeggside"> <img src="hashbrowntext.jpg" class="roundcorn"></label> <label><input type="radio" value="grits" name="threeeggside"> <img src="gritstext.jpg" width="44" height="26" class="roundcorn"></label> <input type="radio" value="ultimate omelette" name="type"> <img src="ultimateomelettetext.jpg" class="roundcorn"> <label> <input type="radio" value="bacon" name="omelettemeat"> <img src="bacontext.jpg" class="roundcorn"></label> <label> <input type="radio" value="ham" name="omelettemeat"> <img src="hamtext.jpg" class="roundcorn"></label> <label><input type="radio" value="white toast" name="omelettetoast"> <img src="/whitetext.jpg" class="roundcorn"></label> <label><input type="radio" value="whole wheat toast" name="omelettetoast"> <img src="wholewheattext.jpg" class="roundcorn"></label> </label><input type="radio" value="pancakes" name="type"> <img src="pancakestext.jpg" class="roundcorn"></label> <label><input type="radio" value="scrambled eggs" name="pancakeegg"> <img src="scrambledtext.jpg" class="roundcorn"></label> <label><input type="radio" value="eggs over easy" name="pancakeegg" > <img src="overeasytext.jpg" class="roundcorn"></label> <label><input type="radio" value="sausage patties" name="pancakemeat" > <img src="sausagepattiestext.jpg" class="roundcorn"></label> <label><input type="radio" value="beef smoked sausage" name="pancakemeat"> <img src="beefsmokedsausagetext.jpg" class="roundcorn"></label>
const typeInputs = document.querySelectorAll(`input[name=type][type=radio]`) // consider other name
const radioInputs = document.querySelectorAll(`input[type=radio]`) // consider other name

typeInputs.forEach(el => el.addEventListener("click", ({ target }) => {
  radioInputs.forEach(input => {
    if (input !== target)
      input.checked = false;
  })
}));

暂无
暂无

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

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