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


当前回答

浏览器忽略只读字段上的自动删除。这段代码使所有可写字段在聚焦之前都是只读的。

$(_=>{$('form[autocomplete=off][name]:not([readonly])').map((i,t)=>$(t).prop('autocomplete',t.type=='密码'?'新密码':'ope').prop;})<script src=“https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js“></script><form method=“post”autocomplete=“off”><input name=“user”id=“user”required class=“表单控件”/><label class=“form label”for=“user”>新用户</label><小时><input type=“password”name=“pass”id=“pass“minlength=”8“maxlength=“20”/><label class=“form label”for=“pass”>新Passwort</label></form>

其他回答

添加autocomplete=“off”不会使其停止。

将输入类型属性更改为type=“search”。谷歌不会对搜索类型的输入应用自动填充。

固定的只需在实际输入字段上方添加

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion-MDNhttps://medium.com/paul-jaworski/turning-off-autocomplete-in-chrome-ee3ff8ef0908-中等在EDGE、Chrome(最新版本63)、Firefox Quantum(57.0.4 64-бит)、Firefox(52.2.0)上测试假字段是chrome/opera自动填充错误字段的一种解决方法

 const fakeInputStyle = {opacity: 0, float: 'left', border: 'none', height: '0', width: '0'}

 <input type="password" name='fake-password' autoComplete='new-password' tabIndex='-1' style={fakeInputSyle} />

<TextField
  name='userName'
  autoComplete='nope'
  ... 
/>

<TextField
      name='password'
      autoComplete='new-password'
      ... 
    />

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

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

了解Firefox(我认为只有Firefox)使用了一个名为ismxfilld的值,该值基本上强制自动完成,这一点很重要。

ismxfilld=“0”表示关闭

or

ismxfilld=“1”表示开启

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

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