form 表单字段 autocomplete 设置为off 后仍然无效的解决方法

The autocomplete attribute is an enumerated attribute. The attribute has two states. The on keyword maps to the on state, and the off keyword maps to the off state. The attribute may also be omitted. The missing value default is the on state. The off state indicates that by default, form controls in the form will have their autofill field name set to "off"; the on state indicates that by default, form controls in the form will have their autofill field name set to "on".

autocomplete属性是表单字段中的HTML5新属性,该属性有两种状态值,分别为"on" 和 "off",该属性可省略:省略属性值后默认值为"on",也可以省略属性名,直接写入关键字on或off。

因为浏览器内部也会默认开启一个输入字段后自动补全的功能,所以在有些情况下我们设置 autocomplete="off" 后会失效。MDN中给出了一个非常棒的tip,我只翻译了相关的这一段:

尽管将autocomplet值设为off,在某些情况下仍会失效。处理这种情况的一个小tip就是将该属性赋一个除on 或 off之外的一个任意的值(你自己可以随便胡诌八扯一个值)。

如下所示:

autocomplete="nope"

这是因为我们胡乱设置的这个值是一个无效的值,因此浏览器会放弃对该属性的执行。

 

 

参考

W3.org: 

https://www.w3.org/TR/html5/forms.html#attr-form-autocomplete

MDN:How to Turn Off Form Autocompletion 

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

你可能感兴趣的:(form 表单字段 autocomplete 设置为off 后仍然无效的解决方法)