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

时间:2014-11-18 13:10:27

标签: html

这让我发疯了。我知道它与标签标签有关。这是我的代码:

 <form method="post" action="includes/loginprocess.php">
    <label for="username">Username: </label>
    <input type="text" name="username" value=''/>

    <label for="password">Password: </label>
    <input type="password" name="password" />

    <input type="submit" name="submit" value="submit" />
</form>

for和name是否相同?

错误是&#34;标签元素的for属性必须引用表单控件。&#34;

1 个答案:

答案 0 :(得分:0)

根据http://www.w3schools.com/tags/att_label_for.asp,标签的for属性的值应该是标签绑定到的元素的id,因此将id属性添加到文本框

<form method="post" action="includes/loginprocess.php">
    <label for="username">Username: </label>
    <input type="text" name="username" id="username" value=''/>

    <label for="password">Password: </label>
    <input type="password" name="password" id="password" />

    <input type="submit" name="submit" value="submit" />
</form>