我有设计问题与谷歌Chrome浏览器和它的形式自动填充功能。 如果Chrome记住了一些登录/密码,它会将背景颜色更改为黄色。

以下是一些截图:

如何删除背景或只是禁用这个自动填充?


当前回答

如果你想完全摆脱它,我已经在之前的回答中调整了代码,使它在悬停,激活和聚焦时也能工作:

input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:active, input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px white inset;
}

其他回答

如果你想完全摆脱它,我已经在之前的回答中调整了代码,使它在悬停,激活和聚焦时也能工作:

input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:active, input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px white inset;
}

在标记中,只需插入这一小行代码。

autocomplete="off"

但是,不要把它放在用户名/电子邮件/idname字段,因为如果你仍然想使用自动完成,它会禁用这个字段。但我找到了一个解决这个问题的方法,简单地把代码放在你的密码输入标签中,因为你永远不会自动完成密码。这个修复应该会移除颜色强制,保持电子邮件/用户名字段的自动完成功能,并让你避免像Jquery或javascript这样的笨重黑客。

解决方案:

if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
    $(window).load(function(){
        $('input:-webkit-autofill').each(function(){
            var text = $(this).val();
            var name = $(this).attr('name');
            $(this).after(this.outerHTML).remove();
            $('input[name=' + name + ']').val(text);
        });
    });
}

我修复了这个问题的密码字段,我有这样:

将输入类型设置为文本而不是密码

使用jQuery删除输入文本值

使用jQuery将输入类型转换为密码

<input type="text" class="remove-autofill">

$('.js-remove-autofill').val('');    
$('.js-remove-autofill').attr('type', 'password');

我用这个,

input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset !important; }
input:focus:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset !important; }
/* You can use color:#color to change the color */