我遇到了chrome自动填充行为的几个形式的问题。

表单中的字段都有非常常见和准确的名称,例如“email”、“name”或“password”,并且它们还设置了autocomplete=“off”。

自动完成标志已经成功禁用了自动完成行为,当你开始输入时,会出现一个下拉的值,但没有改变Chrome自动填充字段的值。

这种行为是可以的,除了chrome填充输入不正确,例如填充电话输入与电子邮件地址。客户抱怨过这个问题,所以它被证实在很多情况下都发生了,而不是我在我的机器上本地操作的某种结果。

目前我能想到的唯一解决方案是动态生成自定义输入名称,然后在后端提取值,但这似乎是一种相当笨拙的解决这个问题的方法。是否有任何标签或怪癖,改变自动填充行为,可以用来解决这个问题?


当前回答

Mike Nelsons提供的解决方案在Chrome 50.0.2661.102 m中不工作。 简单地添加一个与display:none设置相同类型的输入元素不再禁用本机浏览器自动完成功能。现在需要复制希望禁用自动完成的输入字段的name属性。

此外,为了避免输入字段在表单元素中重复,应该在不显示的元素上放置一个disabled。这将阻止该元素作为表单操作的一部分提交。

<input name="dpart" disabled="disabled" type="password" style="display:none;">
<input name="dpart" type="password">
<input type="submit">

其他回答

我想我该把我的药发上去。发现你不能使用显示:没有,所以我想出了一个快速和肮脏的解决方案,只是使假输入小,并将其移出视线。到目前为止一切顺利,直到他们再次打破它。

<input id="FakePassword" type="password" style="float:left;position:relative;height:0;width:0;top:-1000px;/>

因为display none似乎不再起作用了 添加

<input type="text" name="fakeusernameremembered"/>
<input type="password" name="fakepasswordremembered"/>

在一个div溢出隐藏,最大宽度和最大高度0px

所以它就变成了:

<div style="overflow: hidden; max-width: 0px; max-height: 0px;">
    <input type="text" name="fakeusernameremembered"/>
    <input type="password" name="fakepasswordremembered"/>
</div>

乔宾的回答让我吃了一惊。以下是对我有效的方法:

<input type="password" name="password" id="password_fake" style="display:none;" />
<input type="password" name="password"/>

确保不要使用autocomplete="off",否则会破坏解决方案。

我的问题是,Chrome会自动填充邮政编码,在引导自动完成界面,因为我是自动建议可能的值从我的数据库。

我必须做的事情:

将输入字段的id属性更改为“邮政编码”以外的内容 将输入字段的自动完成值更改为false 调用$('#postcode_field').autocomplete(…)我不得不用$('#postcode_field')重置自动完成属性。道具(“自动完成”,“假”);因为Boostrap的自动完成插件会自动将其更改为关闭。

这些问题的其他解决方法对我都不起作用。

唯一管用的想法是这个:

它从元素中删除“name”和“id”属性并为它们赋值 1毫秒后返回。把这个放在文件里,准备好。

$(document).ready(function() {
    $('form[autocomplete="off"] input, input[autocomplete="off"]').each(function () {

                var input = this;
                var name = $(input).attr('name');
                var id = $(input).attr('id');

                $(input).removeAttr('name');
                $(input).removeAttr('id');

                setTimeout(function () {
                    $(input).attr('name', name);
                    $(input).attr('id', id);
                }, 1);
            });
});