'必需'属性不起作用 [英] 'Required' attribute not working

查看:134
本文介绍了'必需'属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近创建了一个网页,让我学习更多关于HTML的知识,并且找到了'required'属性。我将它添加到了字段中,但它没有做任何事情。

I recently created a web page for me to learn more about HTML, and I found the 'required' attribute. I added it to the fields, but it didn't do anything.

任何人都可以告诉我我的 required 属性的错误吗?

Can anyone tell me my mistake for 'required' attribute?

当字段为空时,我希望它说请填写此字段

I want it to say "Please fill this field" when the field is empty

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


推荐答案

请确保您已在第一个表单中提交。
您有多种表格。因此,要求不起作用。

Please make sure you have submit inside the first form. You have multiple forms. Hence required is not working.

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

但是如果你坚持要有多个表格和表格,在提交之前,你可以验证第一个表格。如果我没有错,你试着有一个更好的用户界面布局,可以处理CSS而不是多个表格和表格。

But if you insist in having multiple tables and forms, before submit, you can validate the first form. If I am not wrong, you are trying have a better UI placement which can be dealt with CSS instead of multiple Forms and tables.

这篇关于'必需'属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆