简体   繁体   English

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

[英]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>&nbsp;&nbsp;

here is my actual code 这是我的实际代码

<div>&nbsp;&nbsp;
  <label for="name" style="line-height:24px;">Your Name</label><br>&nbsp;&nbsp;
  <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>&nbsp;&nbsp;
<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”. 控件是由inputtextareabuttonselectobject元素创建的,因此只需将“ 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属性必须引用buttoninput (除了type=hidden ), keygenmeteroutputprogressselect ,或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.

相关问题 验证HTML时出错:label元素的for属性必须引用表单控件 - Error 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? 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 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 标签元素的for属性的值必须是非隐藏表单控件的ID吗? - 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 必须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