如何禁止(表单)用户名、密码自动填充
浏览器一旦遇到 type="password"的控件,就会把密码自动填充到该控件。
解决方案一:
step1:打开IE浏览器
step2:打开Internet选项中的内容,如下
取消勾选即可。
解决方案二:
比如HTML如下:
<input type="password" name="admin_pwd" minlength="6" required="true" /> 在页面初始化的时候 把type改为text 并且清空,在focus事件触发的时候又把type改为password。 $("input[name='admin_pwd']").attr("type", "text").val("").on("focus", function () { $(this).attr("type", "password"); }); 当页面ajax提交后又把type改为text且清空该值 $("input[name='admin_pwd']").attr("type", "text").val("");
解决方案三:
文档加载完毕之后将密码输入框设置为空:
1 window.load = function(){ 2 document.getElementById('密码域ID').value=''; 3 };
解决方案四:
在用户名和密码之间加上一个隐藏的文本框
1 <input type="text" name="name"> 2 <input type="hidden"> 3 <input type="password" name="pass">
解决方案五:
使用HTML5属性
1 <pre name="code" class="html"> 2 <input type="text" name="name" autocomplete="off"> 3 <input type="password" name="pass" autocomplete="off">