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

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


当前回答

目前的解决方案是使用type="search"。谷歌不会对输入的搜索类型应用自动填充。

参见:https://twitter.com/Paul_Kinlan/status/596613148985171968

更新04/04/2016:看起来这是固定的!参见http://codereview.chromium.org/1473733008

其他回答

快速破解,如果你读了上面的答案仍然得到自动补全,你可以试试这个。给出随机字符串将删除自动补全。

<input autocomplete="somerandomstring" or autocomplete="disabled">

我不知道这方法对不对,它就是对我有用。

看到chrome忽略autocomplete="off",我用一个愚蠢的方法解决它,这是使用“假输入”来欺骗chrome填充它,而不是填充“真实的”一个。

例子:

<input type="text" name="username" style="display:none" value="fake input" /> 
<input type="text" name="username" value="real input"/>

Chrome将填充“假输入”,当提交时,服务器将采取“真实输入”的值。

虽然我同意自动补全应该是用户的选择,但有时Chrome对它过于热心(其他浏览器可能也是如此)。例如,具有不同名称的密码字段仍然自动填充已保存的密码,而前一个字段仍然填充用户名。当表单是web应用程序的用户管理表单,而你不想自动填充以填充你自己的凭证时,这尤其糟糕。

Chrome完全忽略autocomplete="off"现在。虽然JS技巧可能很有效,但我发现了一种简单的方法:

将密码字段的值设置为控制字符8 (PHP中的“\x08”或&#8;在HTML)。这将停止Chrome自动填充字段,因为它有一个值,但没有实际的值输入,因为这是退格字符。

是的,这仍然是一个黑客,但它为我工作。YMMV。

TL;DR:告诉Chrome这是一个新的密码输入,它不会提供旧的密码作为自动补全建议:

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

由于设计决定,Autocomplete ="off"不起作用——大量研究表明,如果用户可以将密码存储在浏览器或密码管理器中,他们就会有更长时间和更难破解密码。

自动完成的规范已经改变,现在支持各种值,使登录表单更容易自动完成:

<!-- Auto fills with the username for the site, even though it's email format -->
<input type="email" name="email" autocomplete="username">

<!-- current-password will populate for the matched username input  -->
<input type="password" autocomplete="current-password" />

如果你不提供这些Chrome浏览器仍然试图猜测,当它做它忽略autocomplete="off"。

解决方案是密码重置表单也存在自动完成值:

<label>Enter your old password:
    <input type="password" autocomplete="current-password" name="pass-old" />
</label>
<label>Enter your new password:
    <input type="password" autocomplete="new-password" name="pass-new" />
</label>
<label>Please repeat it to be sure:
    <input type="password" autocomplete="new-password" name="pass-repeat" />
</label>

你可以使用autocomplete="new-password"标志告诉Chrome浏览器不要猜测密码,即使它已经为这个网站存储了一个。

Chrome还可以直接使用凭据API管理网站的密码,这是一个标准,最终可能会得到普遍支持。

在chrome v. 34之后,在<form>标记处设置autocomplete="off"不起作用

我做这些改变是为了避免这种恼人的行为:

删除密码输入的名称和id 在输入中放入一个类(例如:passwordInput)

(到目前为止,Chrome不会把保存的密码输入,但形式现在是破碎的)

最后,为了让表单工作,当用户点击提交按钮时,或者当你想触发表单提交时,运行以下代码:

var sI = $(".passwordInput")[0];
$(sI).attr("id", "password");
$(sI).attr("name", "password");

在我的情况下,我曾经在密码输入中有id="password" name="password",所以我在触发提交之前把它们放回去。