如何使单选按钮每组只能 select 1 个选项?
How do I make a radio button only able to select 1 option per group?
我有 5 个单选按钮组。我希望用户只能 select 每个无线电组中的一个部分。我的第一组工作正常,只 selecting 一个部分,但是当我 select 某些东西而不是 selected 按钮从 1 移动到另一个 selects 时,其他组部分。
我的代码是:
<html>
<head>
<title> Checkboxes and radio buttons assignment 4 </title>
</head>
<body>
<form name=form1>
<h2>Complete the following</h2>
<hr>
Tick the box if you have the following:
<h2>History of Hereditary Disease </h2>
Heart <input type="checkbox" name=chkHeart value="Heart"> <br><br>
Asthma <input type="checkbox" name=chkAsthma value="Asthma">
<br><br>
Arthritis <input type="checkbox" name=chkArthritis
value="Arthritis">
<br>
<hr>
Select the button that describes you:
<h2>Exercise</h2>
<input type="radio" name=radspeed CHECKED onclick="return
Frequently_onclick(0)" value="Frequently"> Frequently
<input type="radio" name=radspeed onclick="return Average_onclick(1)" value="Average"> Average
<input type="radio" name=radspeed onclick="return Seldom_onclick(2)" value="Seldom"> Seldom
<br>
<hr>
<h2>Diet</h2>
<input type="radio" name=Low Fat CHECKED onclick="return LowFat_onclick(0)" value="Low Fat"> Low Fat
<input type="radio" name=Average onclick="return AverageFat_onclick(1)" value="Average"> Average
<input type="radio" name=High Fat onclick="return HighFat_onclick(2)" value="High Fat"> High Fat
<br>
<hr>
<h2>Alcohol</h2>
<input type="radio" name=LightAlcohol CHECKED onclick="return LightAlcohol_onclick(0)" value="Light"> Light
<input type="radio" name=MediumAlcohol onclick="return MediumAlcohol_onclick(1)" value="Medium"> Medium
<input type="radio" name=HeavyAlcholo onclick="return HeavyAlcohol_onclick(2)" value="Heavy"> Heavy
<br>
<hr>
<h2>Smoking</h2>
<input type="radio" name=NonSmoker CHECKED onclick="return NonSmoker_onclick(0)" value="Non-Smoker"> Non-Smoker
<input type="radio" name=LightSmoker onclick="return LightSmoker_onclick(1)" value="Light"> Light
<input type="radio" name=HeavySmoker onclick="return HeavySmoker_onclick(2)" value="Heavy"> Heavy
<br>
<hr>
<h2>General Health</h2>
<input type="radio" name=GoodHealth CHECKED onclick="return GoodHealth_onclick(0)" value="Good"> Good
<input type="radio" name=AverageHealth onclick="return AverageHealth_onclick(1)" value="Average"> Average
<input type="radio" name=PoorHealth onclick="return PoorHealth_onclick(2)" value="Poor"> Poor
<br>
<br>
<hr>
</form>
</body>
</html>
您必须为特定组设置相同的名称。
您的第一组名称相同,而另一组名称不同。
你可以看看Here
我有 5 个单选按钮组。我希望用户只能 select 每个无线电组中的一个部分。我的第一组工作正常,只 selecting 一个部分,但是当我 select 某些东西而不是 selected 按钮从 1 移动到另一个 selects 时,其他组部分。
我的代码是:
<html>
<head>
<title> Checkboxes and radio buttons assignment 4 </title>
</head>
<body>
<form name=form1>
<h2>Complete the following</h2>
<hr>
Tick the box if you have the following:
<h2>History of Hereditary Disease </h2>
Heart <input type="checkbox" name=chkHeart value="Heart"> <br><br>
Asthma <input type="checkbox" name=chkAsthma value="Asthma">
<br><br>
Arthritis <input type="checkbox" name=chkArthritis
value="Arthritis">
<br>
<hr>
Select the button that describes you:
<h2>Exercise</h2>
<input type="radio" name=radspeed CHECKED onclick="return
Frequently_onclick(0)" value="Frequently"> Frequently
<input type="radio" name=radspeed onclick="return Average_onclick(1)" value="Average"> Average
<input type="radio" name=radspeed onclick="return Seldom_onclick(2)" value="Seldom"> Seldom
<br>
<hr>
<h2>Diet</h2>
<input type="radio" name=Low Fat CHECKED onclick="return LowFat_onclick(0)" value="Low Fat"> Low Fat
<input type="radio" name=Average onclick="return AverageFat_onclick(1)" value="Average"> Average
<input type="radio" name=High Fat onclick="return HighFat_onclick(2)" value="High Fat"> High Fat
<br>
<hr>
<h2>Alcohol</h2>
<input type="radio" name=LightAlcohol CHECKED onclick="return LightAlcohol_onclick(0)" value="Light"> Light
<input type="radio" name=MediumAlcohol onclick="return MediumAlcohol_onclick(1)" value="Medium"> Medium
<input type="radio" name=HeavyAlcholo onclick="return HeavyAlcohol_onclick(2)" value="Heavy"> Heavy
<br>
<hr>
<h2>Smoking</h2>
<input type="radio" name=NonSmoker CHECKED onclick="return NonSmoker_onclick(0)" value="Non-Smoker"> Non-Smoker
<input type="radio" name=LightSmoker onclick="return LightSmoker_onclick(1)" value="Light"> Light
<input type="radio" name=HeavySmoker onclick="return HeavySmoker_onclick(2)" value="Heavy"> Heavy
<br>
<hr>
<h2>General Health</h2>
<input type="radio" name=GoodHealth CHECKED onclick="return GoodHealth_onclick(0)" value="Good"> Good
<input type="radio" name=AverageHealth onclick="return AverageHealth_onclick(1)" value="Average"> Average
<input type="radio" name=PoorHealth onclick="return PoorHealth_onclick(2)" value="Poor"> Poor
<br>
<br>
<hr>
</form>
</body>
</html>
您必须为特定组设置相同的名称。
您的第一组名称相同,而另一组名称不同。
你可以看看Here