[英]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
链接起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.