阻止浏览器自动填充input密码框

1.最简单的方法,加一个属性autocomplete=“new-password”.

  <input type="text" placeholder="密码" autocomplete=“new-password”/>

2.把input type=”password” 改成 input type=”text” 并在后面加上 οnfοcus=”this.type=’password’”.

  <input type="text" placeholder="密码" readonly onfocus="this.type=’password'"/>

3.在真正的password前面加一个隐藏的password
特点:这样不会影响用户体验,也可以兼容所有浏览器。

<input style="display:none">
<input type="password" name="password" />

4.首先设置input为只读readonly,当页面加载完成后,浏览器不会自动填充内容,但是也不可以进行编辑。然后我们再用js的定时器延迟一段时间后移除input的只读属性readonly,输入框便可进行再次编辑

  <input type="password" placeholder="密码" readonly onfocus="this.removeAttribute('readonly');"/>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值