html表单和输入未在w3c验证器上验证

时间:2014-01-19 00:01:54

标签: html forms validation

我刚开始使用表单和输入http://www.w3schools.com/html/html_forms.asp并且它们可以正常工作,但是当我通过W3C验证服务运行它们时会导致大量错误。 http://validator.w3.org/#validate_by_input 删除表单和输入时,代码验证正常。我唯一能想到的是,表格和输入并不完全是html,因为我还不知道这个名字是什么 感谢。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>login</title>
    <link type='text/css' rel='stylesheet' href='css/login.css'>
</head>

<body>

    <div id ="header">
        <h1>log in</h1>
    </div>

    <div id ="name">
        <form>
            editors name: <input type="text" name="name">
        </form>
    </div>
    <div id="pswd">
        <form>
            password: <input type="password" name="pwd">
        </form>
    </div>

    <div id="options">
        <h3>Or</h3>
    </div>  
    <div id="wayBack">
        <a href="www.adrianhoulewebprojects.com/easyEdit.html">Return to page</a>   
    </div>

</body>

</html>

1 个答案:

答案 0 :(得分:1)

我认为你想要实现的是......

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>login</title>
    <link type='text/css' rel='stylesheet' href='css/login.css'>
</head>

<body>

    <div id ="header">
        <h1>log in</h1>
    </div>

    <form action="/">
        <div id ="name">
            editors name: <input type="text" name="name">
        </div>
        <div id="pswd">
            password: <input type="password" name="pwd">
        </div>
    </form>

    <div id="options">
        <h3>Or</h3>
    </div>  
    <div id="wayBack">
        <a href="www.adrianhoulewebprojects.com/easyEdit.html">Return to page</a>   
    </div>

</body>

</html>

字段应包含在一个表单中,以便它们一起提交。提出错误是因为将文本(编辑器名称/密码)作为FORM元素的直接子项无效

更具语义性的解决方案是......

<form action="/">
    <div>
        <label for="input_name">editors name:</label>
        <input type="text" name="name" id="input_name" />

        <p>It's completely valid to have text here inside a P tag</p>

        <label for="input_password">password:</label>
        <input type="password" name="password" id="input_password" />
    </div>
</form>

这将允许用户单击标签以聚焦相应的表单字段