我有设计问题与谷歌Chrome浏览器和它的形式自动填充功能。 如果Chrome记住了一些登录/密码,它会将背景颜色更改为黄色。
以下是一些截图:
如何删除背景或只是禁用这个自动填充?
我有设计问题与谷歌Chrome浏览器和它的形式自动填充功能。 如果Chrome记住了一些登录/密码,它会将背景颜色更改为黄色。
以下是一些截图:
如何删除背景或只是禁用这个自动填充?
当前回答
如果你想避免黄色闪烁,直到你的css被应用,拍打一个过渡的坏男孩像这样:
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset !important;
transition: background-color 10s ease-in-out 0s;
}
其他回答
如果你想完全摆脱它,我已经在之前的回答中调整了代码,使它在悬停,激活和聚焦时也能工作:
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:active, input:-webkit-autofill:focus {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
那解决方案呢:
if ($.browser.webkit) {
$(function() {
var inputs = $('input:not(.auto-complete-on)');
inputs.attr('autocomplete', 'off');
setTimeout(function() {
inputs.attr('autocomplete', 'on');
}, 100);
});
}
它会关闭自动完成和自动填充(因此黄色背景消失),等待100毫秒,然后在没有自动填充的情况下将自动完成功能恢复。
如果你有需要自动填充的输入,那么给它们一个自动完成的css类。
没有一个解决方案对我有效,用户名和密码输入仍然在填充,并给出黄色背景。
所以我问自己,“Chrome如何决定在给定的页面上应该自动填充什么?”
“它会查找输入id、输入名称吗?”表单的id吗?表单动作?”
通过我对用户名和密码输入的实验,我发现只有两种方法会导致Chrome无法找到应该自动填充的字段:
1)将密码输入放在文本输入之前。 2)给他们相同的名字和身份证……或者没有姓名和身份证。
页面加载后,用javascript你可以改变页面上输入的顺序,或者动态地给他们他们的名字和id…
Chrome不知道是什么击中了它…自动完成关闭。
疯狂的黑客,我知道。但这对我很有用。
Chrome 34.0.1807.116, OSX 10.7.5
如果你想避免黄色闪烁,直到你的css被应用,拍打一个过渡的坏男孩像这样:
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset !important;
transition: background-color 10s ease-in-out 0s;
}
这是杰森的MooTools版本。修复它在Safari也。
window.addEvent('domready',function() {
$('username').focus();
if ((navigator.userAgent.toLowerCase().indexOf(\"chrome\") >= 0)||(navigator.userAgent.toLowerCase().indexOf(\"safari\") >= 0))
{
var _interval = window.setInterval(function ()
{
var autofills = $$('input:-webkit-autofill');
if (autofills.length > 0)
{
window.clearInterval(_interval); // stop polling
autofills.each(function(el)
{
var clone = el.clone(true,true).inject(el,'after');;
el.dispose();
});
}
}, 20);
}
});