input標籤中autocomplete="off" 失效的解決辦法
阿新 • • 發佈:2018-11-08
在做使用者註冊的時候因為密碼輸入框 input type=“password”造成的,使用者名稱密碼總是自動填充,加上autocomplete="off"也無效,後面找到一種簡單的解決方法,不多說看程式碼:
解決方法:
1、type="password"改成type="text"
2、給input標籤新增自定義屬性 flag="password"
<div class="row cl"> <label class="form-label col-xs-4 col-sm-2">密碼</label> <div class="formControls col-xs-5 col-sm-6"> <input type="text" flag="password"class="input-text" value="" placeholder="請輸入密碼6-24個字元" id="password" name="password"> </div> </div>
3. js處理
$(function(){ //密碼取消填充 $("[flag='password']").focus(function(){ $(this).attr("type","password"); }); })