简体   繁体   English

label元素的for属性必须引用表单控件吗?

[英]The for attribute of the label element must refer to a form control?

I have read the other questions, but i cant seem to apply it to my problem. 我已经阅读了其他问题,但是我似乎无法将其应用于我的问题。

In the validator it is giving me the problem 'The for attribute of the label element must refer to a form control'. 在验证器中,这给了我一个问题:“ label元素的for属性必须引用表单控件”。

Can someone help me out? 有人可以帮我吗? here is my code: 这是我的代码:

<h2>Contact Us</h2>
<form name="contactform" method="post"
      action="http://dev.itas.ca/~christopher.allison/send_form_email.php">
    <table>
        <tr> 
            <td> 
                <label for="first_name">First Name *</label> 
            </td> 
            <td> 
                <input  type="text" name="first_name" maxlength="50" size="30"> 
            </td>
        </tr>
        <tr> 
            <td> 
                <label for="last_name">Last Name *</label> 
            </td> 
            <td> 
                <input  type="text" name="last_name" maxlength="50" size="30"> 
            </td>
        </tr>
        <tr> 
            <td> 
                <label for="email">Email Address *</label> 
            </td> 
            <td> 
                <input  type="text" name="email" maxlength="80" size="30"> 
            </td>
        </tr>
        <tr> 
            <td> 
                <label for="telephone">Telephone Number</label>
            </td> 
            <td> 
                <input  type="text" name="telephone" maxlength="30" size="30"> 
            </td>
        </tr>
        <tr> 
            <td> 
                <label for="comments">Comments *</label> 
            </td> 
            <td > 
                <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center"> 
                <div class="buttonHolder">

                    <input value="Submit" title="submit" name="lucky" type="submit" id="btn_i">
                </div>   
            </td>
        </tr>
    </table>
</form>
</div><!--close form_settings-->

The issue you have is that the for attribute must reference the id attribute of the input instead of the name : 您遇到的问题是, for属性必须引用输入的id属性而不是name

<label for="first_name">First Name *</label> 
<input type="text" id="first_name" name="first_name" maxlength="50" size="30"> 

You can still use the name attribute for whatever you want but to link label with input you need to add an id. 您仍然可以将name属性用于所需的任何内容,但需要将label与需要添加ID的input链接起来。

Check out label documentation. 查看标签文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 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 验证HTML时出错:label元素的for属性必须引用表单控件 - Error validating HTML: The for attribute of the label element must refer to a form control 验证HTML:label元素的for属性必须引用表单控件 - validating HTML: The for attribute of the label element must refer to a 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 为什么label元素具有表单属性? - Why does the label element have a form attribute? 必须HTML <form> 动作属性绝对引用.php文件发送表单数据? - Must the HTML <form> action attribute absolutely refer to a .php file to send form data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM