'必需'属性不起作用

时间:2016-11-20 09:02:52

标签: html

我最近为我创建了一个网页,以了解有关HTML的更多信息,我找到了'required'属性。我把它添加到字段中,但它没有做任何事情。

有人能告诉我“必需”属性的错误吗?

我希望它在字段为空时说“请填写此字段”

<html>
        <head>
            <link href="icon.ico" rel="icon">
            <title>Log In</title>
        </head>
        <body>
            <h1 align="center">Welcome to site</h1>
            <hr width="50%"/>
            <br/>
            <table align="center">
                <form>
                    <tr>
                        <td>Log In : </td>
                        <td><input type="text" name="LogInEmail" placeholder="Enter your email" required></td> </tr><tr>
                        <td>Password : </td>
                        <td><input type="password" name="password" placeholder="Password" required></td>
                    </tr>
                </form>
            </table>
            <br/>
                <table align="center">
                    <form>
                    <tr>
                        <td><input type="submit" value="    Log In    "/></td>
                    </tr>
                </form>
            </table>
        </body>
    </html>

3 个答案:

答案 0 :(得分:2)

请确保您已在第一张表格中提交。 你有多种形式。因此要求不起作用。

    <html>
  <head>
    <link href="icon.ico" rel="icon">
    <title>Log In</title>
  </head>
  <body>
    <h1 align="center">Welcome to site</h1>
    <hr width="50%" />
    <br/>
    <table align="center">
      <form id="form1" runat="server">
        <tr>
          <td>Log In : </td>
          <td>
            <input type="text" name="LogInEmail" placeholder="Enter your email" required>
          </td>
        </tr>
        <tr>
          <td>Password : </td>
          <td>
            <input type="password" name="password" placeholder="Password" required>
          </td>
        </tr>
        <tr>
          <td>
            <input type="submit" value="    Log In    " />
          </td>
        </tr>
      </form>
    </table>
  </body>
</html>

但是如果您坚持拥有多个表格和表单,则在提交之前,您可以验证第一个表单。如果我没有错,那么您正在尝试使用更好的UI布局,可以使用CSS处理而不是使用多个表单和表格。

答案 1 :(得分:2)

你拿了两个表格。你应该把你的提交按钮放在同一个表格中输入要求字段存在。小心表格。

答案 2 :(得分:1)

我遇到了同样的问题,我刚刚替换了提交按钮内的表单它对我有效:)

相关问题