[英]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 235, Column 84: The for attribute of the label element must refer to a form control.
… <label for="name" style="line-height:24px;">Your Name</label><br>
here is my actual code 这是我的实际代码
<div>
<label for="name" style="line-height:24px;">Your Name</label><br>
<input class="css_form_namefield TooltipIstok " type="text" name="name" value="" style="width: 554px;" maxlength="50" >
</div>
If you use the for attribute in a label element it has to match the id of an input element in your form. 如果在标签元素中使用for属性,则它必须与表单中输入元素的ID相匹配。
ie 即
<label for="field-id" style="line-height:24px;">Your Name</label><br>
<input type="text" id="field-id">
This page may be helpful for more information. 此页面可能有助于获取更多信息。 http://www.w3.org/TR/WCAG-TECHS/H44.html
http://www.w3.org/TR/WCAG-TECHS/H44.html
By definition, the for
attribute value must match the id
attribute value of “another” form control, to use the HTML 4.01 terminology. 按照定义,
for
属性值必须与“另一个”表单控件的id
属性值匹配,才能使用HTML 4.01术语。 Controls are created by input
, textarea
, button
, select
, or object
elements, so just read “another” as “a”. 控件是由
input
, textarea
, button
, select
或object
元素创建的,因此只需将“ another”读为“ a”即可。 HTML5 puts this somewhat differently, specifying that the attribute must refer to a labelable element . HTML5对此稍有不同,它指定属性必须引用可标记元素 。
From the error message, it seems that you are validating against HTML5, so the rule that applies is that the for
attribute must refer to a button
, input
(other than with type=hidden
), keygen
, meter
, output
, progress
, select
, or textarea
element. 从错误消息看来,您似乎正在针对HTML5进行验证,因此适用的规则是
for
属性必须引用button
, input
(除了type=hidden
), keygen
, meter
, output
, progress
, select
,或textarea
元素。 My guess is that you just forgot the id
attribute, incorrectly assuming that the name
attribute could do its job. 我的猜测是您只是忘记了
id
属性,而错误地假设name
属性可以完成其工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.