简体   繁体   English

label元素的for属性必须引用非隐藏表单控件<label for=“Country” >Countr</label>

[英]The for attribute of the label element must refer to a non-hidden form control <label for=“Country” >Countr

<div class="needContent">
                    <label for="Country" >Country</label>

                    <input list="browsers" name="Country" required="required">
                    <datalist id="browsers">
                        <option value="Canada">
                        <option value="The United States">
                        <option value="India">
                        <option value="Pakistan">
                        <option value="Germany">
                    </datalist>
                </div>

Hi, I am new to html.I am trying to validate my file on html validator but it is giving me the error specified above. 嗨,我是html的新手,我试图在html验证器上验证我的文件,但这给了我上面指定的错误。 Can someone help me to fix that please? 有人可以帮我解决这个问题吗?

The problem is that the for attribute of <label> corresponds to the element's ID , not its name : 问题是<label>for属性对应于元素的ID ,而不是其name

for

  • The id of a labelable form-related element in the same document as the label element. 与label元素在同一文档中的可标签表单相关元素的id The first such element in the document with an ID matching the value of the for attribute is the labeled control for this label element. 文档中具有与for属性的值匹配的ID的第一个此类元素是此label元素的带标签的控件

To resolve this, all you have to do is give your <input> element an id that is the same as its name . 要解决此问题,您要做的就是为您的<input>元素提供一个与name相同的id Note that you'll probably also want to ensure that both of these are lowercase to prevent confusion: 请注意,您可能还需要确保两者均为小写形式,以防止混淆:

 <div class="needContent"> <label for="country">Country</label> <input list="browsers" id="country" name="country" required="required"> <datalist id="browsers"> <option value="Canada"> <option value="The United States"> <option value="India"> <option value="Pakistan"> <option value="Germany"> </datalist> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 label元素的for属性必须引用非隐藏表单控件 - The for attribute of the label element must refer to a non-hidden form control 表单中的Textarea标签:错误:标签元素的for属性值必须是非隐藏表单控件的ID - Textarea Label in Form: Error: The value of the for attribute of the label element must be the ID of a non-hidden form control 标签元素的for属性的值必须是非隐藏表单控件的ID吗? - The value of the for attribute of the label element must be the ID of a non-hidden form control? 为什么会出现这个错误label元素的for属性值必须是非隐藏表单控件的ID - Why am I getting this error The value of the for attribute of the label element must be the ID of a non-hidden form control label元素的for属性必须引用表单控件吗? - The for attribute of the label element must refer to a form control? label元素的for属性是否必须引用表单控件错误? - The for attribute of the label element must refer to a form control error? 验证HTML时出错:label元素的for属性必须引用表单控件 - Error validating HTML: The for attribute of the label element must refer to a form control 验证HTML:label元素的for属性必须引用表单控件 - validating HTML: The for attribute of the label element must refer to a form control 选择表单中的第一个非隐藏输入 - Selecting the first non-hidden input in a form 为什么label元素具有表单属性? - Why does the label element have a form attribute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM