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

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


当前回答

我遇到过类似的问题,输入字段要么取名字,要么取电子邮件。我设置autocomplete=“关闭”,但Chrome仍然强制建议。事实证明,这是因为占位符文本中有“姓名”和“电子邮件”这两个词。

例如

<input type="text" placeholder="name or email" autocomplete="off" />

我通过在占位符中的单词中放入零宽度的空格来解决这个问题。没有更多的Chrome自动完成。

<input type="text" placeholder="nam&#8203;e or emai&#8203;l" autocomplete="off" />

其他回答

对任何想要解决这个问题的人来说,我终于明白了。

Chrome只服从的自动完成="off"如果页面是HTML5页面(我使用XHTML)。

我把我的页面转换成HTML5,问题就消失了(捂脸)。

经过大量的挖掘,我发现Chrome上的自动完成下拉菜单(版本83.0.4103.116)不显示,当我们删除输入标签上的名称和id属性 如。代码如下所示 < div > < span > 如果没有在输入标签上设置名称和id属性,则自动完成关闭工作 < input type = " text " / > < / span > < span > 自动完成将在这里工作,因为id属性已设置 <input id="name" type="text"/> < / span > < / div >

在Chrome 48+使用这个解决方案:

Put fake fields before real fields: <form autocomplete="off"> <input name="fake_email" class="visually-hidden" type="text"> <input name="fake_password" class="visually-hidden" type="password"> <input autocomplete="off" name="email" type="text"> <input autocomplete="off" name="password" type="password"> </form> Hide fake fields: .visually-hidden { margin: -1px; padding: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip: rect(0, 0, 0, 0); position: absolute; } You did it!

同样,这也适用于旧版本。

我遇到过类似的问题,输入字段要么取名字,要么取电子邮件。我设置autocomplete=“关闭”,但Chrome仍然强制建议。事实证明,这是因为占位符文本中有“姓名”和“电子邮件”这两个词。

例如

<input type="text" placeholder="name or email" autocomplete="off" />

我通过在占位符中的单词中放入零宽度的空格来解决这个问题。没有更多的Chrome自动完成。

<input type="text" placeholder="nam&#8203;e or emai&#8203;l" autocomplete="off" />

[2021年适用于Chrome(v88, 89, 90), Firefox, Brave, Safari] 旧的答案已经写在这里,将适用于试验和错误,但大多数 他们没有链接到任何官方文件或什么Chrome不得不说这一点 的事。

问题中提到的问题是因为Chrome的自动填充功能,这里是Chrome在这个bug链接中的立场- https://bugs.chromium.org/p/chromium/issues/detail?id=468153#c164

简单地说,有两种情况-

[CASE 1]: Your input type is something other than password. In this case, the solution is simple, and has three steps. Add name attribute to input name should not start with a value like email or username, otherwise Chrome still ends up showing the dropdown. For example, name="emailToDelete" shows the dropdown, but name="to-delete-email" doesn't. Same applies for autocomplete attribute. Add autocomplete attribute, and add a value which is meaningful for you, like new-field-name It will look like this, and you won't see the autofill for this input again for the rest of your life - <input type="text/number/something-other-than-password" name="x-field-1" autocomplete="new-field-1" /> [CASE 2]: input type is password Well, in this case, irrespective of your trials, Chrome will show you the dropdown to manage passwords / use an already existing password. Firefox will also do something similar, and same will be the case with all other major browsers. [1] In this case, if you really want to stop the user from seeing the dropdown to manage passwords / see a securely generated password, you will have to play around with JS to switch input type, as mentioned in the other answers of this question.

[1]关于关闭自动补全的详细MDN文档- https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion