2014-01-19 120 views
0

我刚开始使用表单和输入http://www.w3schools.com/html/html_forms.asp,他们工作正常,据我所知,但他们导致一个错误的负载,当我通过W3C验证服务运行它。 http://validator.w3.org/#validate_by_input 代码验证罚款时,我删除表单和输入。我唯一能想到的是,表单和输入不完全是html,因为我还不知道名称= 谢谢。html表单和输入没有验证w3c验证程序

<!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

我想你想达到这是什么?

<!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> 

这将允许用户点击标签为了集中相应的表格字段

+1

您还需要一个'行动'的形式 – ChrisW

+0

我今天学到了东西,我认为这是需要的方法:P – michael

+0

完美,这正是我的试图去做。那么你是否说我不能有一个以上的表格。如果我需要在输入字段之间添加一堆内容,该怎么办? – Adrian