错误验证HTML:本为标签元素的属性必须引用表单控件 [英] Error validating HTML: The for attribute of the label element must refer to a form control

查看:154
本文介绍了错误验证HTML:本为标签元素的属性必须引用表单控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道在检查我的网页在 http://validator.w3.org/check
错误是:

  46号线,68列:本为标签元素的属性必须引用表单控件。
<标签类=环保标签为=environment_form>环境:LT; /标签>

我相信我的外在形式提供给我的标签 id引用,为什么它保持烦我这个错误?

 < D​​IV>
    <表ID =environment_form方法=后>
        < D​​IV CLASS =病急乱投医,选择>
            <标签类=环保标签为=environment_form>环境:LT; /标签>
            <选择名称=environment_dropdown的onchange =对selectionChanged()>
                <选项@(计算机[评选] == NULL || string.IsNullOrEmpty(计算机[评选]的ToString())选择:?)>选择吲; /选项>
                @foreach(型号中的字符串名称){
                    <选项@(!计算机[选择] = NULL&放大器;&安培;计算机[评选]等于(名)选择:)>
                        @名称
                    < /选项>
                }
            < /选择>
        < / DIV>
    < /表及GT;
< / DIV>


你有这样的:

 为=environment_form

和它是指直接在表格!但为属性,应该是指表单中的一个元素,你的情况来选择。因此,添加一个id属性到你的选择和改变了,这样的FO例如:

 <标签类=环保标签为=environment_dropdown>环境:LT; /标签>
<选择名称=environment_dropdownID =environment_dropdown的onchange =对selectionChanged()>

I don't know why I keep getting this error while checking my page at http://validator.w3.org/check The error was:

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?

<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. So add an "id" attribute to your select and change the "for", like this fo example :

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

这篇关于错误验证HTML:本为标签元素的属性必须引用表单控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆