提交时检查密码
我有一个基本的注册表单:
<form action="adduser" method="post" onsubmit='passwordCheck()'>
Email Address: <input type="email" name="email" required autocomplete="on" placeholder="[email protected]"/><br/>
Username: <input type="text" name="username" maxlength=25 required placeholder="JoyfulSophia"/><br/>
Password: <input type="password" name="password" id='password' onkeydown='checkPassword()' maxlength=30 required placeholder="**********" />
Password (Again): <input type='password' id='pass_repeat'/>
<br/>
<br/>
<input type="submit" value="Send" /> <input type="reset">
</form>
因此,当提交表单时,它会调用passwordCheck(),它会根据容易猜到的密码对其进行测试,不重复相同的密码等。它将错误(如果有)放入 < p>
(未显示)。 checkPassword() 有效并且错误显示正确,但表单仍然提交,而我读过的 JS 文档说如果 onsubmit 返回 false,则表单不应提交。
为什么 checkPassword() 返回 false 时表单正在提交?此外,密码输入中的每次击键都不会调用 checkPassword()。
I have a basic signup form:
<form action="adduser" method="post" onsubmit='passwordCheck()'>
Email Address: <input type="email" name="email" required autocomplete="on" placeholder="[email protected]"/><br/>
Username: <input type="text" name="username" maxlength=25 required placeholder="JoyfulSophia"/><br/>
Password: <input type="password" name="password" id='password' onkeydown='checkPassword()' maxlength=30 required placeholder="**********" />
Password (Again): <input type='password' id='pass_repeat'/>
<br/>
<br/>
<input type="submit" value="Send" /> <input type="reset">
</form>
So when the form is submitted, it calls passwordCheck(), which tests it against easily guessable passwords, not repeating the same password etc. It puts the error, if any, in a <p>
(not shown). checkPassword() works and the error is displaying correctly, but the form still submits while JS docs that I've read say that if onsubmit returns false, the form should not submit.
Why is the form submitting when checkPassword() returns false? Also, checkPassword() is not being called on each keystroke in the passwords input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要
对于 onkeydown, 检查您的 checkPassword() 函数是否确实被调用。让它做一个alert()或类似的事情。
It needs to be
as for the onkeydown, check that your checkPassword() function is actually being called. have it do an alert() or something similar.
添加退货
Add return