8

我不知道为什么在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>

我相信我为我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>
4

1 回答 1

26

你有这个:

for="environment_form"

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

<label class="environment-label" for="environment_dropdown">Environments:</label>
<select name="environment_dropdown" id="environment_dropdown" onchange="selectionChanged()">
于 2012-07-19T18:59:21.753 回答