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'">