【发布时间】:2012-01-03 08:04:25
【问题描述】:
我有一个基本的注册表单:
<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(),它会针对容易猜到的密码进行测试,而不是重复相同的密码等。如果有错误,它会将错误(如果有)放在 <p>(未显示)中。 checkPassword() 有效并且错误显示正确,但是表单仍然提交,而我读过的 JS 文档说如果 onsubmit 返回 false,则表单不应该提交。
为什么checkPassword()返回false时表单提交?此外,在密码输入中的每次击键时都不会调用 checkPassword()。
【问题讨论】:
标签: javascript forms passwords onsubmit