如何通过选择特定的单选按钮组来重置多个单选按钮组
How can I reset many radio button groups by selecting a specific radio button group
我在下面有三个不同的组,名为 "type"。在这些组下面是具有不同名称的其他按钮组。当我选择任何 "type" 命名的单选按钮时,我想清除(重置)所有其他可能在所选的 "type" 组单选按钮旁边被选中的单选按钮。
<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;
})
}));
<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;
})
}));