如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?
当前回答
三个选项:
第一:
<input type='text' autocomplete='off' />
第二:
<form action='' autocomplete='off'>
第三个(JavaScript代码):
$('input').attr('autocomplete', 'off');
其他回答
当我自己尝试时,事情已经改变了,旧的答案不再有效。
我确信它会奏效。我在Chrome、Edge和Firefox中测试了这一功能,它确实做到了这一点。你也可以尝试一下,告诉我们你的经历。
set the autocomplete attribute of the password input element to "new-password"
<form autocomplete="off">
....other element
<input type="password" autocomplete="new-password"/>
</form>
这是根据MDN
如果您正在定义一个用户管理页面,用户可以在该页面中为另一个人指定新密码,因此您希望防止自动填充密码字段,则可以使用autocomplete=“新密码”
这是一个提示,哪些浏览器不需要遵守。然而,由于这个原因,现代浏览器已经停止使用autocomplete=“new password”自动填充<input>元素。
如果仅自动完成=“off”不起作用,也可以尝试以下操作:
autocorrect="off" autocapitalize="off" autocomplete="off"
固定的只需在实际输入字段上方添加
https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion-MDNhttps://medium.com/paul-jaworski/turning-off-autocomplete-in-chrome-ee3ff8ef0908-中等在EDGE、Chrome(最新版本63)、Firefox Quantum(57.0.4 64-бит)、Firefox(52.2.0)上测试假字段是chrome/opera自动填充错误字段的一种解决方法
const fakeInputStyle = {opacity: 0, float: 'left', border: 'none', height: '0', width: '0'}
<input type="password" name='fake-password' autoComplete='new-password' tabIndex='-1' style={fakeInputSyle} />
<TextField
name='userName'
autoComplete='nope'
...
/>
<TextField
name='password'
autoComplete='new-password'
...
/>
我刚刚遇到了这个问题,并尝试了几次失败,但这一次对我有效(在MDN上找到):
在某些情况下,浏览器将继续建议自动完成值即使autocomplete属性设置为off。这是意外的对于开发人员来说,这种行为可能非常令人困惑。真正的诀窍强制无完成是将随机字符串分配给属性像这样:
autocomplete="nope"
在这次谈话中,没有一个解决方案对我有效。
我终于找到了一个纯HTML解决方案,它不需要任何JavaScript,可以在现代浏览器中工作(除了Internet Explorer;至少要有一个捕获,对吗?),并且不需要对整个表单禁用自动完成。
只需关闭表单上的自动完成功能,然后为您希望在表单中工作的任何输入打开它。例如:
<form autocomplete="off">
<!-- These inputs will not allow autocomplete and Chrome
won't highlight them yellow! -->
<input name="username" />
<input name="password" type="password" />
<!-- This field will allow autocomplete to work even
though we've disabled it on the form -->
<input name="another_field" autocomplete="on" />
</form>
推荐文章
- 使伸缩项目正确浮动
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击