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

尽管输入字段和表单字段都有autocomplete="off"属性,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>

浏览器检测从这里开始。

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

其他回答

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

<form autocomplete="off">
   <input id="xyz" />
</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版本34现在忽略autocomplete=off, 看到这个。

很多关于这是好事还是坏事的讨论?你的观点是什么?

在尝试了所有的解决方案后,这里是什么似乎是chrome版本:45,与表单有密码字段:

 jQuery('document').ready(function(){
        //For disabling Chrome Autocomplete
        jQuery( ":text" ).attr('autocomplete','pre'+Math.random(0,100000000));
 });

我遇到过类似的问题,输入字段要么取名字,要么取电子邮件。我设置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" />