HTML收音机按钮

时间:2016-08-23 09:32:10

标签: html

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'?

谢谢,一个非常noobie的问题,但任何指针或帮助表示赞赏。

4 个答案:

答案 0 :(得分:1)

我认为,您忘记写名称)所有无线电输入的名称必须相同,例如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>

答案 1 :(得分:0)

您必须为单选按钮定义名称

像这样

<input type = "radio" id="activitylevel" name="activitylevel" value="sedentary">

答案 2 :(得分:0)

您需要设置每个输入字段名称,然后在尝试检索值时引用该名称。例如:

<input type = "radio" name="activitylevel">Sedentary - Little or no exercise, desk job</option><br>

答案 3 :(得分:0)

提交表单时,不会提交没有姓名的输入。因此,您需要为输入添加名称。似乎也存在一些语法错误。更正后的代码如下所示:`

<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>`