[英]HTML Radio Buttons
Activity Level<br>
<input type = "radio" id="activitylevel" value="sedentary">Sedentary - Little or no exercise, desk job</option><br>
<input type = "radio" id="activitylevel" value="lightly">Lightly active - Light exercise or sports 1-3 days/wk</option><br>
<input type = "radio" id="activitylevel" value="moderately">Moderately active Moderate exercise or sports 3-5 days/wk</option><br>
<input type = "radio" id="activitylevel" value="very">Very active - Hard exercise or sports 6-7 days/wk</option><br>
<input type = "radio" id="activitylevel" value="extremely">Extremely Active - Hard daily exercise or sports & physical labor job or 2 X day training, football camp, etc.</option><br>
这有什么问题吗? 我花了一个小时查看我的其余代码,弄清楚了为什么我不能提取在此表单上发送的值,我开始认为这段代码有问题。 有任何想法吗? 我在网上看过示例,它们不使用“ id”吗?
谢谢,这是一个非常好的问题,但是希望您能提供一些指导或帮助。
我认为,您忘了写名字了)所有广播输入的名字必须相同,例如name="radio_name"
。 像下面这样写。 但是html中的id
不能相同。 以及为什么您使用我不明白。
<input type="radio" name="activitylevel" id="activitylevel_1" value="sedentary">Sedentary - Little or no exercise, desk job<br>
<input type = "radio" name="activitylevel" id="activitylevel_2" value="lightly">Lightly active - Light exercise or sports 1-3 days/wk<br>
<input type = "radio" name="activitylevel" id="activitylevel_3" value="moderately">Moderately active Moderate exercise or sports 3-5 days/wk<br>
<input type = "radio" name="activitylevel" id="activitylevel_4" value="very">Very active - Hard exercise or sports 6-7 days/wk<br>
<input type = "radio" name="activitylevel" id="activitylevel_5" value="extremely">Extremely Active - Hard daily exercise or sports & physical labor job or 2 X day training, football camp, etc.<br>
您必须定义单选按钮的名称
像这样
<input type = "radio" id="activitylevel" name="activitylevel" value="sedentary">
您需要设置每个输入字段的名称,然后在尝试检索值时引用该名称。 例如:
<input type = "radio" name="activitylevel">Sedentary - Little or no exercise, desk job</option><br>
提交表单时,将不提交没有名称的输入。 因此,您需要在输入中添加名称。 也似乎有一些语法错误。 更正后的代码如下所示:
<input type = "radio" id="activitylevel1" value="sedentary" name="activitylevel">Sedentary - Little or no exercise, desk job</input>
<input type = "radio" id="activitylevel2" value="lightly" name="activitylevel">Lightly active - Light exercise or sports 1-3 days/wk</input>
<input type = "radio" id="activitylevel3" value="moderately" name="activitylevel">Moderately active Moderate exercise or sports 3-5 days/wk</input>
<input type = "radio" id="activitylevel4" value="very" name="activitylevel">Very active - Hard exercise or sports 6-7 days/wk</input>
<input type = "radio" id="activitylevel5" value="extremely" name="activitylevel">Extremely Active - Hard daily exercise or sports & physical labor job or 2 X day training, football camp, etc.</input>`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.