Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 只有一个值需要在表单上提交_Html_Forms - Fatal编程技术网

Html 只有一个值需要在表单上提交

Html 只有一个值需要在表单上提交,html,forms,Html,Forms,我有一个包含这些字段的表单,出于某种原因,尽管您选择了“否”单选按钮,但出席人数仅显示为“是” 你知道我所做的有什么问题吗 <label> <input type="radio" name="attendance" value="No" id="attendance" /> Yes</label> <label> <input type="radio" name="attendance" value="Yes" id="

我有一个包含这些字段的表单,出于某种原因,尽管您选择了“否”单选按钮,但出席人数仅显示为“是”

你知道我所做的有什么问题吗

<label>
    <input type="radio" name="attendance" value="No" id="attendance" />
    Yes</label> 
<label>
  <input type="radio" name="attendance" value="Yes" id="attendance" />
    No</label>

对
不

两个元素不能有相同的
id
。删除
id
或分配不同的
id


<label>
    <input type="radio" name="attendance" value="No" id="attendance" />
    No</label> 
<label>
  <input type="radio" name="attendance" value="Yes" id="attendance" />
    Yes</label>
不 对
您的标签是
No
,而单选按钮的值是
Yes
:)

也正如其他人所指出的:不能有两个元素具有相同的
id
。您可以使用
类来实现此目的。

使用此类:

<label>
    <input type="radio" name="attendance" value="Yes" id="attendance-yes" />
    Yes</label> 
<label>
  <input type="radio" name="attendance" value="No" id="attendance-no" />
    No</label>

对
不

您的标签和值被颠倒了…

一个
id
应该是唯一的,因此您应该为元素赋予不同的标识

我不确定这是否是问题的原因,但这是您显示的代码中唯一的错误。如果这没有帮助,那么问题出在代码中没有显示的部分



正如其他人所提到的,您在单选按钮之间交换了值和标签,但这似乎太明显了…

我在给出的代码中看到两个错误:

  • 标签标签应仅围绕有效标签(而不是输入标签)
  • 这两个项目有相同的id,我想这就是为什么你总是得到相同的结果

您可以区分ID,因为它应该是唯一的。您还可以将属性
用于标签标记

像这样:

<label for="attendanceyes">
    <input type="radio" name="attendance" value="Yes" id="attendanceyes" />
    Yes
</label>

<label for="attendanceno">
    <input type="radio" name="attendance" value="No" id="attendanceno" />
    No
</label>

对
不

为什么有两个元素具有相同的ID?如果发生这种情况,代码中必须有更多的元素。这应该和你期望的一样。我只是回答了同样的问题,但你实际上还没有修复他的代码;)@乔斯佩·西尔伯:但我是第一个P你打错了…:DLet的《打散孩子们的战斗》,PeeHaa得到了这样一个:P-1 A
标签
可能围绕着
输入
:我更喜欢用标签包装我的输入(大部分),这样我就不用在标签上写
for
属性了。具有相同ID的P.S对服务器并不重要,因为只返回名称和值。
但这似乎太明显了。这再明显不过了!:-)-1当
标签
s围绕
输入
s时,它们不需要
for
属性: