如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?


当前回答

始终有效的解决方案

我用随机字符解决了与谷歌Chrome的无休止斗争。当您总是使用随机字符串呈现自动完成时,它将永远不会记住任何内容。

<input name="name" type="text" autocomplete="rutjfkde">

希望这对其他人有所帮助。

2022年更新:

Chrome做出了这一改进:autocomplete=“新密码”,这将解决这个问题,但我不确定,如果一段时间后Chrome再次将其更改为不同的功能。

其他回答

了解Firefox(我认为只有Firefox)使用了一个名为ismxfilld的值,该值基本上强制自动完成,这一点很重要。

ismxfilld=“0”表示关闭

or

ismxfilld=“1”表示开启

在这次谈话中,没有一个解决方案对我有效。

我终于找到了一个纯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>

添加autocomplete=“off”不会使其停止。

将输入类型属性更改为type=“search”。谷歌不会对搜索类型的输入应用自动填充。

这对我有用。

<input name="pass" type="password" autocomplete="new-password" />

我们也可以在文本、选择等其他控件中使用此策略

用只读存储器贴出的答案很聪明,很管用。

但当我使用Bootstrap时,只读输入字段被标记为灰色背景,直到被聚焦。当文档加载时,您可以通过简单地锁定和解锁输入来欺骗浏览器。

因此,我有一个想法将其实现到jQuery解决方案中:

jQuery(document).ready(function () {
    $("input").attr('readonly', true);
    $("input").removeAttr('readonly');
});