是否有 W3C 有效的方法来禁用 HTML 表单中的自动完成功能? [英] Is there a W3C valid way to disable autocomplete in a HTML form?

查看:35
本文介绍了是否有 W3C 有效的方法来禁用 HTML 表单中的自动完成功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 xhtml1-transitional.dtd doctype 时,使用以下 HTML 收集信用卡号

When using the xhtml1-transitional.dtd doctype, collecting a credit card number with the following HTML

<input type="text" id="cardNumber" name="cardNumber" autocomplete='off'/>

将在 W3C 验证器上标记警告:

will flag a warning on the W3C validator:

没有属性自动完成".

是否有 W3C/标准方法来禁用浏览器对表单中敏感字段的自动完成功能?

Is there a W3C / standards way to disable browser auto-complete on sensitive fields in a form?

推荐答案

这里 很好来自 MDC 的文章解释了形成自动完成的问题(和解决方案).Microsoft 也发布了类似的内容此处.

Here is a good article from the MDC which explains the problems (and solutions) to form autocompletion. Microsoft has published something similar here, as well.

老实说,如果这对您的用户很重要,那么以这种方式打破"标准似乎是合适的.例如,亚马逊使用了相当多的 'autocomplete' 属性,它似乎运行良好.

To be honest, if this is something important to your users, 'breaking' standards in this way seems appropriate. For example, Amazon uses the 'autocomplete' attribute quite a bit, and it seems to work well.

如果您想完全删除警告,您可以使用 JavaScript 使用 someForm.setAttribute( "autocomplete", "off" ) 将该属性应用于支持它的浏览器(IE 和 Firefox 是重要的浏览器);someFormElm.setAttribute( "autocomplete", "off" );

If you want to remove the warning entirely, you can use JavaScript to apply the attribute to browsers that support it (IE and Firefox are the important browsers) using someForm.setAttribute( "autocomplete", "off" ); someFormElm.setAttribute( "autocomplete", "off" );

最后,如果您的网站使用 HTTPS,IE 会自动关闭自动完成功能(据我所知,其他一些浏览器也是如此).

Finally, if your site is using HTTPS, IE automatically turns off autocompletion (as do some other browsers, as far as I know).

更新

由于这个答案仍然获得了相当多的支持,我只想指出,在 HTML5 中,您可以在表单元素上使用自动完成"属性.请参阅 W3C 上的文档.

As this answer still gets quite a few upvotes, I just wanted to point out that in HTML5, you can use the 'autocomplete' attribute on your form element. See the documentation on W3C for it.

这篇关于是否有 W3C 有效的方法来禁用 HTML 表单中的自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆