首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“‘Required”属性无效

“‘Required”属性无效
EN

Stack Overflow用户
提问于 2016-11-20 09:02:52
回答 2查看 19.4K关注 0票数 2

最近,我创建了一个网页,让我了解更多关于HTML的信息,并找到了'required'属性。我把它加到地里,但它什么也没做。

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

当字段为空时,我希望它写上“请填写此字段”。

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-20 09:12:27

请确保你已在第一份表格内提交。你有多种表格。因此所需的是不起作用的。

代码语言:javascript
复制
<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而不是多个表单和表。

票数 4
EN

Stack Overflow用户

发布于 2016-11-20 10:32:54

您接受了两个form.You,应该将提交按钮放置在相同的表单中,输入要求字段exist.Be小心使用表单。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40702308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档