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

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


当前回答

在Chrome和Firefox上工作和测试成功的唯一解决方案是用一个具有autocomplete="off"的表单来包装输入,如下所示:

<form autocomplete="off">
   <input id="xyz" />
</form>

其他回答

我使用Chrome -版本64.0.3282.140(正式版本)(64位),并使用以下代码和表单名称,它适用于我。

<form name="formNameHere">....</form>
<script type="text/javascript">
    setTimeout(function(){
        document.formNameHere.reset();
    },500);
</script>

我发现这个解决方案是最合适的:

function clearChromeAutocomplete()
{
// not possible, let's try: 
if (navigator.userAgent.toLowerCase().indexOf('chrome') >= 0) 
{
document.getElementById('adminForm').setAttribute('autocomplete', 'off'); 
setTimeout(function () {
        document.getElementById('adminForm').setAttribute('autocomplete', 'on'); 
}, 1500);
}
}

它必须在dom就绪后加载,或者在表单呈现后加载。

我已经找到了另一个解决方案-只是用style="-webkit-text-security: disc;"遮住你的autocomplete="off"输入中的字符。 你也可以像下面这样把它添加到你的CSS规则中:

[autocomplete="off"] {
  -webkit-text-security: disc;
}

主要目标是从元素中消除type="password"或其他类似的类型属性。

至少在2021年1月24日,这个解决方案是有效的……

我把这种方法称为大锤方法,但它似乎在我尝试过的所有其他方法都失败的地方起了作用:

<input autocomplete="off" data-autocomplete-ninja="true" name="fa" id="fa" />

注意:输入名称和id属性不应该包含任何会给浏览器提示数据是什么的东西,否则这个解决方案将无法工作。例如,我使用“fa”而不是“FullAddress”。

和下面的脚本页面加载(这个脚本使用JQuery):

$("[data-autocomplete-ninja]").each(function () {
    $(this).focus(function () {
        $(this).data("ninja-name", $(this).attr("name")).attr("name", "");
    }).blur(function () {
        $(this).attr("name", $(this).data("ninja-name"));
    });
});

上面的解决方案应该可以防止浏览器自动填充从其他表单收集的数据,或者从同一表单上以前提交的数据。

基本上,当输入处于焦点中时,我删除了name属性。只要在元素处于焦点时不做任何需要name属性的事情,比如根据元素名称使用选择器,这个解决方案应该是无害的。

对于这个问题,我使用了这个css解决方案。这对我很有用。

input{
  text-security:disc !important;
  -webkit-text-security:disc !important;
  -moz-text-security:disc !important;
}