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


当前回答

autocomplete='off'对我不起作用,无论如何,我将输入字段的value属性设置为一个空格,即<input-type='text'name='username'value=“”>,将默认输入字符设置为空格,由于用户名为空,密码也被清除。

其他回答

我已经解决了在页面加载后放置此代码的问题:

<script>
var randomicAtomic = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
  $('input[type=text]').attr('autocomplete',randomicAtomic);
</script>

我使用此TextMode=“password”autocomplete=“new password”,并在aspx txtPassword.Attributes.Add(“value”,“”)中加载页面;

您可以在输入中使用它。

例如

<input type=text name="test" autocomplete="off" />

最佳解决方案:

防止自动完成用户名(或电子邮件)和密码:

<input type="email" name="email"><!-- Can be type="text" -->
<input type="password" name="password" autocomplete="new-password">

阻止自动完成字段:

<input type="text" name="field" autocomplete="nope">

说明:autocomplete在<input>中继续工作,autocomplete=“off”不工作,但您可以将off更改为随机字符串,如nope。

工作地点:

铬:49、50、51、52、53、54、55、56、57、58、59、60、61、62、63和64Firefox:44、45、46、47、48、49、50、51、52、53、54、55、56、57和58

我遇到了同样的问题,今天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上进行了测试