输入空值时停止提交
我正在寻找一个简单的解决方案来阻止登录表单提交空输入字段。 表格的代码如下。 如果可能的话,我想使用一个简单的 Javascript 解决方案。
<form id="login" method="post" action="">
<input type="text" name="email" id="email" />
<input type="password" name="pwd" id="pwd" />
<button type="submit" id="submit">Login</button>
</form>
如果可能的话,我还想更改空字段的边框。
提前致谢。
Im Looking for a simple solution to stop a login form from submitting with empty input fields. The code for the form is below. I would like to use a simple Javascript soluiton if possible.
<form id="login" method="post" action="">
<input type="text" name="email" id="email" />
<input type="password" name="pwd" id="pwd" />
<button type="submit" id="submit">Login</button>
</form>
If possible I would also like to change the border of the empty field(s).
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
带有虚拟检查的示例代码:
Sample code with dummy checks:
可能的方法:
#
,onsubmit
编辑:要使其对非 JavaScript 用户也适用,请在加载页面时插入
#
操作。Possible approach:
#
onsubmit
of the formEdit: To make this even work for non-javascript users insert the
#
-action when page is loaded.为了保持最小化,我只会使用:
Granted - 不会向用户指出什么问题,但会有所帮助。
To keep it minimal I would just use:
Granted - doesn't point out what's amiss to the user, but works a treat.