浏览器设置记住密码后,密码框清除密码自动填入

914 阅读1分钟

autocomplete='off',autocomplete='new-password' 都不管用的时候
首先设置 type="text"

                       <input
                        type="text"
                        autocomplete='off'
                        data-type="receive"
                        class="inputBlock form-control receive__pwd"
                      />
     // 聚焦的时候变为password --password清除浏览器的自动填入
              $(".delivery__pwd,.receive__pwd").off("input").on("focus",function(e){
                  e.preventDefault()
                  $(this).on("input",function(){
                    if(!$(this).val()){
                        $(this).attr("readonly","true")
                        $(this).blur()
                        let _this = this
                        setTimeout(()=>{
                          $(_this).attr("readonly",false)
                          $(_this).attr("type","text")
                          $(this).focus()
                        },0)
                    }else{
                      $(this).attr("type","password")
                    }
                  })
              })
            $(".delivery__pwd,.receive__pwd").on("click",function(){
              $(this).attr("readonly",false)
              $(this).focus()
            })
            $(".delivery__pwd,.receive__pwd").on("mousedown",function(e){
              if(!$(this).val()){
                e.preventDefault()
                $(this).blur()
                setTimeout(()=>{
                  $(this).focus()
                },0)
                return
              }
            })
          // 失焦校验
          $('.delivery__pwd,.receive__pwd').on('blur',function(){
            $(this).attr("readonly",true)
            // 其他操作
          })