chrome 不记录填写值_【转载】禁用自动填表'autocomplete=off'在Chrome 中不起作用...
我們在表單輸入框中輸入信息,提交表單后,當(dāng)我們再次進(jìn)入表單頁面,雙擊輸入框時(shí),會(huì)出現(xiàn)之前提交的信息,這是因?yàn)闉g覽器一般會(huì)記錄下輸入框之前提交表單的信息。這就是這篇文章要講的autocomplete.
AutoComplete控件就是指用戶在文本框輸入前幾個(gè)字母或是漢子的時(shí)候,該控件就能從存放數(shù)據(jù)的文本或是數(shù)據(jù)庫里將所有以這些字母開頭的數(shù)據(jù)提升給用戶,供用戶選擇,提供方便。
輸入框(input,textarea,
select)的AutoComplete的默認(rèn)值是on,其含義代表是否讓瀏覽器自動(dòng)記錄之前輸入的值。
有時(shí)用戶不希望記錄之前輸入的值,這時(shí)就需要關(guān)閉AutoComplete。
1.
我們通過在form表單上加入,或者對(duì)一些輸入框單獨(dú)加入,就能達(dá)到關(guān)閉AutoComplete的目的。
1.1 在form表單上加入.
<form?method="post"?action="login.php"?name="login"?autocomplete="off">
form>
1.2 在輸入框中加入
<input?id="username"?type="text"?name="username"?maxlength="20"?autocomplete="off">
2.
但是有一種情況例外,就是表單中有input[type="password"],點(diǎn)擊保存密碼后,在Chrome瀏覽器則自動(dòng)填充了用戶名和密碼的輸入框,而IE和Firefox則不同。為了統(tǒng)一瀏覽器樣式,我們需要就Chrome的問題修改。
提供3鐘解決方法
2.1 修改value值
(function(){
if(navigator.userAgent.toLowerCase().indexOf("chrome")
!= -1){
var?selectors?=?document.getElementsByTagName("input");
for(var?i=0;i<selectors.length;i++){
if((selectors[i].type?!==?"submit")?&&?(selectors[i].type?!==?"password")){
selectors[i].value?=?"
";
}
}
setTimeout(function(){
for(var?i=0;i<selectors.length;i++){
if(selectors[i].type?!==?"submit"){
selectors[i].value?=?"";
}
}
},100)
}
})()
2.2 修改disabled屬性
(function(){
if(navigator.userAgent.toLowerCase().indexOf("chrome") !=
-1){
var?selectors?=?document.getElementsByTagName_r("input");
for(var?i=0;i
if((selectors[i].type?!==?"submit")?&&?(selectors[i].type?!==?"password")){
selectors[i].disabled=?true;
}
}
setTimeout(function(){
for(var?i=0;i
if(selectors[i].type?!==?"submit"){
selectors[i].disabled=?false;
}
}
},100)
}
})()
2.3?removes "name" and "id" attributes
(function(){
if(navigator.userAgent.toLowerCase().indexOf("chrome")?!=?-1){
var?selectors?=?document.getElementsByTagName("input");
for(var?i=0;i<selectors.length;i++){
if((selectors[i].type?!==?"submit")?&&?(selectors[i].type?!==?"password")){
var?input?=?selectors[i];
var?inputName?=?selectors[i].name;
var?inputid?=?selectors[i].id;
selectors[i].removeAttribute("name");
selectors[i].removeAttribute("id");
setTimeout(function(){
input.setAttribute("name",inputName);
input.setAttribute("id",inputid);
},1)
}
}
}
})()
個(gè)人比較推薦第三種方法,通過移除input的name和id來達(dá)到效果
總結(jié)
以上是生活随笔為你收集整理的chrome 不记录填写值_【转载】禁用自动填表'autocomplete=off'在Chrome 中不起作用...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python控制命令行光标位置_pyth
- 下一篇: dubbo protocol port