简体   繁体   English

验证HTML时出错:label元素的for属性必须引用表单控件

[英]Error validating HTML: The for attribute of the label element must refer to a form control

I don't know why I keep getting this error while checking my page at http://validator.w3.org/check The error was: 我不知道为什么我在http://validator.w3.org/check检查我的页面时一直收到此错误错误是:

Line 46, Column 68: The for attribute of the label element must refer to a form control. 
<label class="environment-label" for="environment_form">Environments:</label>

I believe I provided an id reference for my label to the outer form, why it keep bugging me about this error? 我相信我为我的label提供了外部表格的id引用,为什么它一直在告诉我这个错误?

<div>
    <form id="environment_form" method="post">
        <div class="styled-select">
            <label class="environment-label" for="environment_form">Environments:</label>
            <select name="environment_dropdown" onchange="selectionChanged()">
                <option @(ViewData["selection"] == null || string.IsNullOrEmpty(ViewData["selection"].ToString()) ? "selected" : "")>select one</option>
                @foreach (string name in Model) { 
                    <option @(ViewData["selection"] != null && ViewData["selection"].Equals(name) ? "selected" : "")> 
                        @name
                    </option>
                }
            </select> 
        </div>
    </form>
</div>

you have this : 你有这个:

for="environment_form"

and it refers to the form directly ! 它直接指的是形式! But the "for" attribute should refer to an element of your form, in your case to the select. 但是“for”属性应该引用表单中的元素,在您的情况下应该引用select。 So add an "id" attribute to your select and change the "for", like this fo example : 因此,在您的选择中添加“id”属性并更改“for”,如下例所示:

<label class="environment-label" for="environment_dropdown">Environments:</label>
<select name="environment_dropdown" id="environment_dropdown" onchange="selectionChanged()">

暂无
暂无

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

相关问题 验证HTML:label元素的for属性必须引用表单控件 - validating HTML: 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? 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 non-hidden form control 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 表单中的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 为什么会出现这个错误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 标签元素的for属性的值必须是非隐藏表单控件的ID吗? - The value of the for attribute of the label element must be the ID of a non-hidden form control? 必须HTML <form> 动作属性绝对引用.php文件发送表单数据? - Must the HTML <form> action attribute absolutely refer to a .php file to send form data? 为什么label元素具有表单属性? - Why does the label element have a form attribute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM