Pet*_*ter 5 html browser forms autocomplete
如何在主要浏览器中禁用特定输入和/或完整表单的自动完成功能.
我找到了这个解决方案
<input type="text" name="foo" autocomplete="off" />
Run Code Online (Sandbox Code Playgroud)
但是,这似乎并不适用于所有浏览器.我在firefox中遇到过问题.
编辑:
我的firefox问题已经解决了.这留下了以下内容:我可以在表单上禁用自动完成功能,还是必须为每个输入提供autocomplete ="off"
Autocomplete应该使用以下<input>类型:文本,搜索,网址,电话,电子邮件,密码,日期选择器,范围和颜色.
但很可惜,你可以尝试添加autocomplete='off'到您的<form>标签,而不是的<input>标签,除非有什么东西阻止你这样做.
如果这不起作用,您也可以使用JavaScript:
if (document.getElementsByTagName) {
var inputElements = document.getElementsByTagName(“input”);
for (i=0; inputElements[i]; i++) {
if (inputElements[i].className && (inputElements[i].className.indexOf(“disableAutoComplete”) != -1)) {
inputElements[i].setAttribute(“autocomplete”,”off”);
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者在jQuery中:
$(document).ready(function(){
$(':input').live('focus',function(){
$(this).attr('autocomplete', 'off');
});
});
Run Code Online (Sandbox Code Playgroud)