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

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

问题描述

使用xhtml1-transitional.dtd文档类型时,使用以下HTML收集信用卡号码

 <输入类型=textid =cardNumbername =cardNumberautocomplete ='off'/> 

会在W3C验证器上标记一个警告:


没有属性autocomplete。

是否有W3C /标准方式禁用浏览器在表单中的敏感字段上自动完成?

这里是来自MDC的一篇很好的文章,它解释了形成自动完成的问题(和解决方案)。
Microsoft发布了类似的此处 。老实说,如果这对你的用户来说很重要,那么以这种方式打破标准似乎是合适的。例如,亚马逊使用'autocomplete'属性相当多,它似乎很好。



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



最后,如果您的网站使用HTTPS,IE会自动关闭自动填充就像我知道的那样)。



更新



因为这个答案仍然有很多upvotes,我只想指出,在HTML5中,你可以在你的表单元素上使用'autocomplete'属性。请参阅W3C的文档


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'/>

will flag a warning on the W3C validator:

there is no attribute "autocomplete".

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

解决方案

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.

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.

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" );

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

Update

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天全站免登陆