'必需'属性不起作用

编程入门 行业动态 更新时间:2024-10-19 22:20:04
本文介绍了'必需'属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近创建了一个网页,让我学习更多关于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.

更多推荐

'必需'属性不起作用

本文发布于:2023-11-11 22:59:23,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!