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


当前回答

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

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

其他回答

大多数答案都没有帮助,因为浏览器只是忽略了它们。(其中一些不兼容跨浏览器)。对我有效的修复方法是:

<form autocomplete="off">
    <input type="text" autocomplete="new-password" />
    <input type="password" autocomplete="new-password" />
</form>

我在表单标签上设置autofill=“off”,在不需要自动填充的地方设置autofil=“new password”。

只需设置autocomplete=“off”。这样做有一个很好的理由:您希望提供自己的自动完成功能!

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

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

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

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        try {
            $("input[type='text']").each(
                function(){
                   $(this).attr("autocomplete", "off");
                });
        }
        catch (e) {
        }
    });
</script>