2013-05-28 95 views
1

我一直在網上搜索這方面的信息,並找到了很多實現這個的例子,但它們都沒有用於我,我希望它讓瀏覽器要求保存密碼並在給出用戶名時,自動完成密碼。我有這樣的:在瀏覽器中記住密碼和自動完成密碼

<form id="LoginForm"> 
     <label>UserName: </label> 
     <input id="user" type="text" name="user" maxlength="16" class="inputTextLogIn"/>        
     <label>Password: </label> 
     <input id="pass" type="password" name="pass" maxlength="16" class="inputTextLogIn"/> 
     <button id='loginButton' href='index.php?module=welcome' type='submit'>Entrar</button> 
</form> 

Javascript代碼來驗證:

$("#LoginForm").validate({ 
       event: "blur", 
       rules: { 
        'user': { 
         required: true, 
         maxlength: 50 
        }, 
        'pass': { 
         required: true, 
         maxlength: 12 
        } 
       }, 
       messages: { 
        'user': "Usuario debe ser válido", 
        'pass': "Contraseña debe ser válida" 
       }, 
       errorElement: "label", 
       submitHandler: function(form){ 
        return doClick($("#loginButton"), $(form).serialize()); 
       } 
     }); 

第一次,瀏覽器索要保存密碼,並自動完成它,今後一段時期,它不,我失去了什麼? ??

+0

你應該確保打開自動完成 – aaronman

+2

_「我希望它能夠使瀏覽器請求保存您的密碼,並在提供用戶名時,自動完成密碼。「_ - 對不起,但這不是現代瀏覽器中已有的內置功能嗎?我不明白爲什麼你會想在這裏手動實現任何東西... – CBroe

+0

是的,我認爲它是一個內置的功能,爲大多數瀏覽器。 –

回答

1

@Subbu是在正確的道路上,你是很近......

因此HTML5是用來告訴該字段是自動完成的,能夠在瀏覽器特定的標籤。只需在表單標記中啓用自動填充功能,並將其打開所有字段即可。

下面是它看起來像使用形式:

<form id="LoginForm" autocomplete="on"> 
     <label>UserName: </label> 
     <input id="user" type="text" name="user" maxlength="16" class="inputTextLogIn"/>        
     <label>Password: </label> 
     <input id="pass" type="password" name="pass" maxlength="16" class="inputTextLogIn"/> 
     <button id='loginButton' href='index.php?module=welcome' type='submit'>Entrar</button> 
</form> 

然後,每當用戶會回來的頁面,它會填充用戶名和密碼。如果由於某種原因,你不想一個字段來填充,只是把自動完成了,就像這樣:

<input id="pass" type="password" name="pass" maxlength="16" class="inputTextLogIn" autocomplete="off"/>