如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?


当前回答

Chrome计划支持这一点。

目前,最好的建议是使用很少自动完成的输入类型。

Chrome讨论

<input type='search' name="whatever" />

要与Firefox兼容,请使用normalautocomplete='off'

<input type='search' name="whatever" autocomplete='off' />

其他回答

<!-- html -->
<input id="inputID" onfocus="this.readOnly = false;" ontouchstart="this.readOnly = false;" onblur="this.readOnly = true;" />

More

javascript和jQuery版本

要禁用表单中文本的自动完成,请使用和元素的自动完成属性。您需要该属性的“off”值。

这可以在完整表单或特定元素中完成:

将autocomplete=“off”添加到元素以禁用整个表单的自动完成。为表单的特定元素添加autocomplete=“off”。

form

<form action="#" method="GET" autocomplete="off">
</form>

输入

<input type="text" name="Name" placeholder="First Name" autocomplete="off">

我遇到了同样的问题,今天2019年10月9日,我找到的唯一解决方案是

将autocomplete=“off”添加到表单标记中。

打开表单标签后输入1个错误。

<input id="username" style="display:none" type="text" name="fakeusernameremembered">

但它在密码类型字段上不起作用,请尝试

<input type="text" oninput="turnOnPasswordStyle()" placeholder="Enter Password" name="password" id="password" required>

在脚本上

function turnOnPasswordStyle() {
    $('#password').attr('type', "password");
}

这在Chrome-78、IE-44、Firefox-69上进行了测试

这对我来说就像一种魅力。

将表单的自动完成属性设置为关闭添加虚拟输入字段,并将其属性设置为禁用。

<form autocomplete=“off”><input-type=“text”autocomplete=“off”style=“display:none”></form>

为了解决这个问题,我使用了一些CSS技巧和以下工作。

input {
    text-security:disc;
    -webkit-text-security:disc;
    -mox-text-security:disc;
}

请阅读本文了解更多详情。