我有一個基本的註冊表單:檢查密碼的onsubmit
<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()。