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


当前回答

目前我找到的解决方案都没有带来真正有效的回应。

具有自动完成属性的解决方案不起作用。

所以,这是我为自己写的:

<input type="text" name="UserName" onkeyup="if (this.value.length > 0) this.setAttribute('type', 'password'); else this.setAttribute('type', 'text');" >

您应该对页面上希望作为密码类型的每个输入字段执行此操作。

这是有效的。

干杯

其他回答

不幸的是,大多数浏览器都删除了此选项,因此无法禁用密码提示。

直到今天,我还没有找到解决这个问题的好办法。我们现在剩下的是希望有一天这种选择会回来。

在这次谈话中,没有一个解决方案对我有效。

我终于找到了一个纯HTML解决方案,它不需要任何JavaScript,可以在现代浏览器中工作(除了Internet Explorer;至少要有一个捕获,对吗?),并且不需要对整个表单禁用自动完成。

只需关闭表单上的自动完成功能,然后为您希望在表单中工作的任何输入打开它。例如:

<form autocomplete="off">
    <!-- These inputs will not allow autocomplete and Chrome
         won't highlight them yellow! -->
    <input name="username"  />
    <input name="password" type="password" />
    <!-- This field will allow autocomplete to work even
         though we've disabled it on the form -->
    <input name="another_field" autocomplete="on" />
</form>

为字段使用非标准的名称和id,因此“name”不是“name_”。浏览器将不会将其视为名称字段。

最好的一点是,您可以对某些但不是所有字段执行此操作,并且它将自动完成某些但不是全部字段。

如果仅自动完成=“off”不起作用,也可以尝试以下操作:

autocorrect="off" autocapitalize="off" autocomplete="off"

我通过添加两个假输入并赋予它们绝对位置来阻止Chrome 66自动填充:

<form style="position: relative">
  <div style="position: absolute; top: -999px; left: -999px;">
    <input name="username" type="text" />
    <input name="password" type="password" />
  </div>
  <input name="username" type="text" />
  <input name="password" type="password" />

起初,我尝试添加display:none;但Chrome忽略了这些输入,并自动填充可见的输入。