我最近创建了一个网页来学习更多关于 HTML 的知识,我发现'required'
属性。我将其添加到字段中,但它没有执行任何操作。
谁能告诉我我的错误'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>
请确保您已在第一份表格中提交。
你有多种形式。因此所需的不起作用。
<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 而不是多个表单和表格来处理。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)