禁用input自动补全,模拟type=password输入字符显示为星号
最近遇到一个想禁用浏览器的密码自动补全的功能,翻遍了整个技术论坛大多使用用auto-complete="new-password"但是本人测试不怎么管用,所有又找到了如下几种方法,特此记录
一、使用span 替换输入内容
根据该地址input密码框输入后设置显示为星号或其他样式 做了一个模拟,
核心片段如下:
<template>
<div class="text-input" :class="right ? 'textinput-right' : ''">
<span
v-if="star"
class="pwd-txt"
:style="right ? { paddingRight: '5px' } : { paddingLeft: '5px' }"
>
{{ passwordType === 'password' ? '*'.repeat(text.length) : text }}
</span>
<input
ref="inputText"
v-model="value"
:style="[
star ? '' : { paddingLeft: '5px' },
right ? { textAlign: 'right' } : ''
]"
:class="['text', className]"
:type="type === 'number' ? 'tel' : 'text'"
:placeholder="text ? '' : placeholder"
:maxlength="maxlength"
@keyup="handelKeyup"
/>
<span v-show="text" class="show-pwd" @click="showPwd">
<svg-icon
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
/>
</span>
<el-button
class="my-btn"
icon="el-icon-unlock"
:loading="unlockLoading"
@click="unlock"
></el-button>
</div>
</template>

二、使用text-security:disc
后来又根据这个js禁止chrome保存密码、更新密码
将上面的案例修改如下:
<template>
<div class="text-input">
<input
v-model.trim="inputVal"
:class="['input-content', className]"
type="text"
:maxlength="maxlength"
:placeholder="placeholder"
oncontextmenu="return false"
onpaste="return false"
oncopy="return false"
oncut="return false"
auto-complete="off"
:style="
isPwd
? 'text-security:disc; -webkit-text-security:disc;ime-mode:disabled'
: ''
"
@keyup.enter.native="unlock"
/>
<span v-show="inputVal" class="show-pwd" @click="showPwd">
<svg-icon :icon-class="isPwd ? 'eye' : 'eye-open'" />
</span>
<el-button
class="my-btn"
icon="el-icon-unlock"
:loading="unlockLoading"
@click="unlock"
></el-button>
</div>
</template>

最大的问题就是目前只有webkit内核可以,没办法兼容其他浏览器
瞧firefox—>

三、使用font-family: text-security-disc
最后:再stackoverflow发现了这个帖子How to make input type=“tel” work as type=“password”从中发训了一个使用font-family: text-security-disc来达到效果

安装以上的text-security
npm i -S text-security
或者直接index.html引用
<link href="https://noppa.github.io/assets/text-security/text-security.css" rel="stylesheet" type="text/css">
最后又将上面片段改为:
<template>
<div class="text-input">
<input
v-model.trim="inputVal"
:class="['input-content', className, isPwd ? 'input-plugins' : '']"
type="text"
:maxlength="maxlength"
:placeholder="placeholder"
auto-complete="off"
@keyup.enter="unlock"
/>
<span v-show="inputVal" class="show-pwd" @click="showPwd">
<svg-icon :icon-class="isPwd ? 'eye' : 'eye-open'" />
</span>
<el-button
class="my-btn"
icon="el-icon-unlock"
:loading="unlockLoading"
@click="unlock"
></el-button>
</div>
</template>
最后整合上面几次修改,预览效果如下:

完整demo请移步https://github.com/dengxiaoning/similar-input-password
禁用input自动补全,模拟type=password输入字符显示为星号的更多相关文章
- ElasticSearch 实现分词全文检索 - 搜素关键字自动补全(Completion Suggest)
目录 ElasticSearch 实现分词全文检索 - 概述 ElasticSearch 实现分词全文检索 - ES.Kibana.IK安装 ElasticSearch 实现分词全文检索 - Rest ...
- vim自动补全
Vim 中使用 OmniComplete 为 C/C++ 自动补全 OmniComplete 并不是插件的名字,而是 Vim 众多补全方式中的一种(全能补全).说白了 OmniComplete 其实就 ...
- Eclipse自动补全功能轻松设置 || 不需要修改编辑任何文件
本文介绍如何设置Eclipse代码自动补全功能.轻松实现输入任意字母均可出现代码补全提示框. Eclipse代码自动补全功能默认只包括 点"." ,即只有输入”." ...
- Debian sudo自动补全
解决 debian sudo TAB 键不能自动补全命令的原因 一般情况,命令行输入 sudo apt-get ins 按 tab ,它后面会自动补全为 install 如果右面写了包的名的一部分,按 ...
- 转:Eclipse自动补全功能轻松设置
Eclipse自动补全功能轻松设置 || 不需要修改编辑任何文件 2012-03-08 21:29:02| 分类: Java | 标签:eclipse 自动补全 设置 |举报|字号 订阅 ...
- 给 zsh 自定义命令添加参数自动补全
有时我会自定义一些 zsh 命令,以便提升某些高频操作的效率.本文记录我给一个自定义命令添加参数自动补全的方法. 场景 我自定义了一个 zsh 命令 gmt,执行 gmt <b2>,可以将 ...
- jquery input 搜索自动补全、typeahead.js
最近做个一个功能需要用到自动补全,然后在网上找了很久,踩了各种的坑 最后用typeahead.js这个插件,经过自己的测试完美实现 使用方法:在页面中引入jquery.jquery.typeahead ...
- 知问前端——自动补全UI
自动补全(autocomplete),是一个可以减少用户输入完整信息的UI工具.一般在输入邮箱.搜索关键字等,然后提取出相应完整字符串供用户选择. 调用autocomplete()方法 var hos ...
- jquery 自动补全控件(支持IE6)待整理
自动补全控件(兼容IE6):http://bassistance.de/ download地址:http://jquery.bassistance.de/autocomplete/jquery.aut ...
- 仿Google首页搜索自动补全
仿Google自动补全,实现细节: 后台是简单的servlet(其实就是负责后台处理数据交互的,没必要非跌用个struts...什么的) 传输介质:xml 使用jQuery js框架 功能实现: 如果 ...
随机推荐
- Javaweb学习笔记第五弹
preparedStatement 防止SQL注入:将敏感字符进行转义 1.获取PreparedStatement对象 String sql="selct * from 表名 where 列 ...
- mysql中exists的用法简答
前言在日常开发中,用mysql进行查询的时候,有一个比较少见的关键词exists,我们今天来学习了解一下这个exists这个sql关键词的用法,这样在工作中遇到一些特定的业务场景就可以有更加多样化的解 ...
- 【VSC】ERROR:GDB exited unexpectedly.
[VSC]ERROR:GDB exited unexpectedly. 记录一次调试所遇bug的查找历程 问题描述 ERROR: GDB exited unexpectedly. Debugging ...
- DevOps|研发效能不是老板工程,是开发者服务
有人说研发效能是老板工程.不是的,研发效能不是老板工程,它不直接服务于老板(虽然老板可能看一些报表),反而是服务于广大产研运(产品+研发+质量+运维)的同学,所以有的公司也把研发效能叫做基础中台,平台 ...
- Windows 10 G 神州网信政府版
神州网信政府版2018版:Win10 CMGE_V0-H.1020.000.iso校验码:9484e568c6505f9c4ad5b9fcf7ec8d83588eebfb38089f53e33011 ...
- day12-SpringBoot数据库操作
SpringBoot数据库操作 1.JDBC+HikariDataSource 在SpringBoot 2.x项目中,默认使用Hikari连接池管理数据源.相比于传统的 C3P0 .DBCP.Tomc ...
- dart基础---->函数传值
1. string type main(List<String> args) { String name = "huhx"; changIt(name); print( ...
- 原生请求 js、jquery封装的ajax请求、axios请求与fetch请求区别与优缺点
原生JS请求 现代浏览器,最开始与服务器交换数据,都是通过XMLHttpRequest对象.它可以使用JSON.XML.HTML和text文本等格式发送和接收数据. 首先我们先把原生的请求封装一下: ...
- OSM(OpenStreetMap)全球路网数据下载方式介绍
本文对OpenStreetMap(OSM)网页与各类OSM数据的多种下载方式加以详细介绍,并对不同数据下载方式加以对比. OSM数据包含道路与铁路路网.建筑.水体.土地利用.兴趣点.行政区边界 ...
- 【原创】Ubuntu Pro 中的RealTime linux(Real-time Ubuntu/PREEMPT-RT/ubuntu官方PREEMPT-RT)
[原创]Ubuntu Pro 订阅中的realtime linux(Real-time Ubuntu/PREEMPT-RT) 目录 [原创]Ubuntu Pro 订阅中的realtime linux( ...