input標簽在谷歌瀏覽器記住密碼下的一個自動填充BUG


Chrome自帶記住密碼功能,帶來了極大方便

但是在點擊保存之后,input標簽會自動填充所保存的密碼,如下圖:

而且填充得很亂,密碼不一定就會填充在密碼框里。解決這一個BUG,可以用下面這個方案:

例如我們有個input標簽:

1 <input type="text" class="test" id="test"> 

首先在這個input標簽上面加一個display為none的input標簽

1 <input type="text"style="display: none">  
2 <input type="text" class="test" id="test">

然后為input加一個autocomplete="off"的屬性,此屬性是 HTML5 的新屬性,自動完成允許瀏覽器預測對字段的輸入,但是只只用於text, search, url, telephone, email, password, datepickers, range 以及 color類型的<input>和<form>,所以如果我們需要一個密碼框,需要給input設置一個onfocus="this.type='password'" 

1 <input type="text" class="test" id="test" style="display: none";>  
2 <input type="text" class="test" id="test" placeholder="請輸入密碼" autocomplete="off" onfocus="this.type='password'">  

 


免責聲明!

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



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