我有一个基本的注册表单:
<form action="adduser" method="post" onsubmit='passwordCheck()'>
Email Address: <input type="email" name="email" required autocomplete="on" placeholder="fr@star.com"/><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(),它会根据容易猜到的密码来测试它,而不是重复相同的密码等。它会将错误(如果有)放在 a <p>
(未显示)中。checkPassword() 有效并且错误显示正确,但是表单仍然提交,而我读过的 JS 文档说如果 onsubmit 返回 false,则表单不应该提交。
为什么 checkPassword() 返回 false 时表单提交?此外,在密码输入中的每次击键时都不会调用 checkPassword()。