阻止浏览器记住密码功能

有两个方法,一个是改type属性的值,一个是增加readonly属性

1、把type='password' 改为 type='text',然后在onfocus事件中把type改为password

<input type="text" onfocus="this.type='password'">

2、给input加上readonly属性,然后在onfocus事件中把readonly属性移除。

<input type="password" readonly  onfocus="if(this.hasAttribute('readonly')){      this.removeAttribute('readonly');this.blur();this.focus();}" >

最后两行代码是为了适配手机版safari浏览器,不加的话虚拟键盘不会弹出来。

参考链接:

http://www.w3.org/2000/svg

https://stackoverflow.com/questions/2530/how-do-you-disable-browser-autocomplete-on-web-form-field-input-tag#answer-24247840

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容