輕松實現ajax登錄時讓瀏覽器保存密碼


將登錄頁面由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>

改完之后一試,問題竟然如此輕松地被解決了,嘿嘿。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM