加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 23:40:57 所属栏目:资源 来源:网络整理
导读:我不知道为什么我在 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"Environment
我不知道为什么我在 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>

我相信我为我的标签提供了外部表格的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>

解决方法

你有这个:
for="environment_form"

它直接指的是表格!但是“for”属性应该引用表单中的元素,在您的情况下应该引用select.因此,在您的选择中添加“id”属性并更改“for”,如下例所示:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读