阻止浏览器自动填充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');"/>
posted @ 2024-02-23 15:34  夜微热  阅读(104)  评论(0编辑  收藏  举报