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

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


当前回答

更新

现在Chrome似乎忽略了style="display: none;"或style="visibility: hidden; "属性。

你可以把它改成这样:

<input style="opacity: 0;position: absolute;">
<input type="password" style="opacity: 0;position: absolute;">

根据我的经验,Chrome只自动完成第一个<input type="password">和前一个<input>。所以我添加了:

<input style="display:none">
<input type="password" style="display:none">

到<form>的顶部,该情况得到解决。

其他回答

2020 年 3 月

我正面临着这个问题,不幸的是,没有一个解决方案对我有效。所以我用了这个小技巧,效果很好。

<input autocomplete="off" type="password" name="password" id="password" readonly="readonly">

$('#password').on('click', function (event) {
  $('#password').removeAttr('readonly');
  $('#password').focus();
});

$('#password').on('blur', function (event) {
  $('#password').attr('readonly', 'readonly');
});

当你点击密码输入字段,它开始显示建议,但当触发重点输入字段比它不显示建议,所以这就是我如何解决我的问题。

我希望它能帮助到一些人。

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

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

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

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

你可以使用下面的概念来实现AutoComplete='false' chrome以及其他浏览器。取一个虚拟输入类型,它的不透明度为0。默认chrome浏览器已经触发第一个已经隐藏。

<input style="opacity: 0; position: absolute; z-index: -1;" name="email">
<input type="search" name="email" class="form-control" autocomplete="new-email" id="email">

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执行自动填充。

我不得不在drupal页面上用一个巨大的webform来解决这个问题。因为我不能编辑每个输入的html代码,所以我想出了下面的通用jQuery解决方案。

<script>

    // Form Autocomplete FIX
    function is_mobile() {
        if( screen.width < 500 || navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
            return true;
        }
        return false;
    }
    jQuery( 'input[autocomplete="off"]' ).each( function() {
        if( is_mobile() ) {
            return;
        }
        jQuery( this ).attr( 'readonly', true );
    } );
    jQuery( 'input[autocomplete="off"]' ).focus( function() {
        if( is_mobile() ) {
            return;
        }
        jQuery( this ).removeAttr( 'readonly' );
        jQuery( this ).focus();
    } );
    jQuery( 'input[autocomplete="off"]' ).blur( function() {
        if( is_mobile() ) {
            return;
        }
        jQuery( this ).attr( 'readonly', true );
    } );

</script>

浏览器检测从这里开始。

我想有可能优化这段代码(我很想获得一些建议),但您将从中获得想法。