是
element.style.display = "none"
function showApples() {
const form = document.querySelector("form");
const apples = form.elements["apples"];
const appleCultivars = form.querySelector("fieldset:nth-of-type(2)");
apples.addEventListener("click", showApples);
if (apples.checked) {
appleCultivars.style.display = "";
} else {
appleCultivars.style.display = "none";
}
}
<body onLoad="showApples()">
<form>
<fieldset>
<legend>Fruits</legend>
<label><input type="radio" name="fruits" id="apples">Apples</label>
<label><input type="radio" name="fruits" id="oranges">Oranges</label>
<label><input type="radio" name="fruits" id="bananas">Bananas</label>
</fieldset>
<fieldset>
<legend>Apples</legend>
<label><input type="radio" name="apple" id="braeburn">Braeburn</label>
<label><input type="radio" name="apple" id="macoun">Macoun</label>
<label><input type="radio" name="apple" id="cortland">Cortland</label>
</fieldset>
</form>
</body>
我知道在堆栈溢出上有一些类似的问题和答案,但是没有一个看起来很优雅,或者在jQuery中。