我一直在网上搜索有关此内容的信息,并找到了很多示例来实现此目的,但没有一个对我有用,我希望它让浏览器要求保存您的密码,并在给出用户名时,自动完成密码。我有这个:
<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());
}
});
第一次,浏览器要求保存密码并自动完成密码,下次,它不会,我错过了什么???
最佳答案
@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"/>
关于javascript - 记住密码并在浏览器中自动完成密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16782022/