我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。

尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。


当前回答

2021更新:将<input type="text">更改为<input type="search" autocomplete="off" >

仅此而已。保留下面的答案作为怀旧。


为了一个可靠的解决方案,你可以添加以下代码到你的布局页面:

<div style="display: none;">
 <input type="text" id="PreventChromeAutocomplete" 
  name="PreventChromeAutocomplete" autocomplete="address-level4" />
</div>

Chrome尊重autocomplete=off只有当至少有一个其他输入元素的形式与任何其他自动完成值。

这对密码字段不起作用——这些在Chrome中的处理方式非常不同。详情见https://code.google.com/p/chromium/issues/detail?id=468153。

更新:Chromium团队于2016年3月11日关闭了“无法修复”的Bug。请参阅我最初提交的错误报告中的最后一条评论,以获得完整的解释。TL;DR:使用语义自动补全属性,如autocomplete="new-street-address",以避免Chrome执行自动填充。

其他回答

Autocomplete ="off"通常有效,但并非总是如此。它取决于输入字段的名称。像“地址”,“电子邮件”,“姓名”这样的名称将被自动补全(浏览器认为他们帮助用户),而像“代码”,“pin”这样的字段将不会被自动补全(如果设置了autocomplete="off")

我的问题是-自动完成是混乱的谷歌地址助手

我通过重命名来修复它

<input type="text" name="address" autocomplete="off">

to

<input type="text" name="the_address" autocomplete="off">

铬71测试。

Autocomplete =off在现代浏览器中基本上被忽略了——主要是由于密码管理器等。

你可以尝试添加这个autocomplete="new-password",它不是所有浏览器都完全支持,但在一些浏览器上是有效的

对于这个问题,我有一个近乎完美的解决方案: 从所有密码输入元素中删除"type=password",在所有这些元素都加载到DOM后,给一个超时来设置"type=password"。Chrome会忽略 改变类型为自动填充。例子:

setTimeout(()=>{ele.type="password"},3000)

或者通过事件改变类型:

ele.oninput=function(){ele.type="password"}

除了给它一个自动补全的假字段外,所有的解决方案都不起作用。我做了一个React组件来解决这个问题。

import React from 'react'

// Google Chrome stubbornly refuses to respect the autocomplete="off" HTML attribute so
// we have to give it a "fake" field for it to autocomplete that never gets "used".

const DontBeEvil = () => (
  <div style={{ display: 'none' }}>
    <input type="text" name="username" />
    <input type="password" name="password" />
  </div>
)

export default DontBeEvil

以下是我在Chrome版本51.0.2704.106上的工作方式。<input id="user_name" type="text" name="user_name" autocomplete="off" required /> And in combination with <input id="user_password" type="password" name="user_password" autocomplete="new-password" required />。我的问题是,在实现new-password之后,它仍然会在user_name字段上显示用户名的下拉列表。