將登錄頁面由form提交改為ajax提交,發現一個副作用——登錄時瀏覽器不會提示是否保存密碼,這樣每次登錄都要輸入用戶名/密碼。
html代碼如下:
<script> $(function () { $('#signin').bind('click', function () { //ajax提交代碼 }); }); </script> <div class="block"> <label>登錄用戶名</label> <input type="text" id="loginName" value=""/> </div> <div class="block"> <label>密碼</label> <input type="password" id="password" value="" /> </div> <div class="block"> <input type="button" id="signin" /> </div>
這個副作用讓人甚是郁悶。
后來揣摩了一下,估計瀏覽器是根據表單提交事件來決定是否提示保存密碼。試試欺騙一下瀏覽器,有form,有submit按鈕,但在onsubmit時return false。
於是html代碼改在了這樣:
<form method="post" onsubmit="return false;"> <div class="block"> <label>登錄用戶名</label> <input type="text" id="loginName" value=""/> </div> <div class="block"> <label>密碼</label> <input type="password" id="password" value="" /> </div> <div class="block"> <input type="submit" id="signin" /> </div> </form>
改完之后一試,問題竟然如此輕松地被解決了,嘿嘿。。。