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


当前回答

这里提到的黑客在Chrome中没有一个对我有用。这里讨论了这个问题:https://code.google.com/p/chromium/issues/detail?id=468153#c41

将其添加到<form>中(至少目前如此):

<div style="display: none;">
    <input type="text" id="PreventChromeAutocomplete" name="PreventChromeAutocomplete" autocomplete="address-level4" />
</div>

其他回答

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

除了

autocomplete="off"

使用

readonly onfocus="this.removeAttribute('readonly');"

对于不希望他们记住表单数据(用户名、密码等)的输入,如下所示:

<input type="text" name="UserName" autocomplete="off" readonly 
    onfocus="this.removeAttribute('readonly');" >

<input type="password" name="Password" autocomplete="off" readonly 
    onfocus="this.removeAttribute('readonly');" >

您可以在属性name how电子邮件地址中向表单添加名称,并生成电子邮件值。例如:

<form id="something-form">
  <input style="display: none" name="email" value="randomgeneratevalue"></input>
  <input type="password">
</form>

如果使用此方法,Google Chrome将无法插入自动填充密码。

<input autocomplete="off" aria-invalid="false" aria-haspopup="false" spellcheck="false" />

我发现它在所有浏览器上都适用。当我只使用自动完成时,它不起作用,除非我组合了您看到的所有属性。此外,我还从谷歌表单输入字段获得了解决方案

三个选项:

第一:

<input type='text' autocomplete='off' />

第二:

<form action='' autocomplete='off'>

第三个(JavaScript代码):

$('input').attr('autocomplete', 'off');