如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?
当前回答
<script language="javascript" type="text/javascript">
$(document).ready(function () {
try {
$("input[type='text']").each(
function(){
$(this).attr("autocomplete", "off");
});
}
catch (e) {
}
});
</script>
其他回答
2022年9月
一些浏览器,如Google Chrome,甚至不关心autocomplete属性的值。停止获取建议的最佳方法是将输入的name属性更改为随时间变化的属性
截至2022年9月,浏览器将不提供一次性密码自动完成功能
所以我们可以使用otp作为域名。
<input name=“otp”>
我的解决方案是使用angular js指令动态更改文本输入类型它就像魅力一样
首先添加2个隐藏文本字段
然后添加一个像这样的角度指令
(function () {
'use strict';
appname.directive('changePasswordType', directive);
directive.$inject = ['$timeout', '$rootScope', '$cookies'];
function directive($timeout, $rootScope, $cookies) {
var directive = {
link: link,
restrict: 'A'
};
return directive;
function link(scope,element) {
var process = function () {
var elem =element[0];
elem.value.length > 0 ? element[0].setAttribute("type", "password") :
element[0].setAttribute("type", "text");
}
element.bind('input', function () {
process();
});
element.bind('keyup', function () {
process();
});
}
}
})()
然后在需要阻止自动完成的文本字段中使用它
<input type="text" style="display:none">\\can avoid this 2 lines
<input type="password" style="display:none">
<input type="text" autocomplete="new-password" change-password-type>
注意:不要忘记包含jquery,并在开始时设置type=“text”
<form name="form1" id="form1" method="post"
autocomplete="off" action="http://www.example.com/form.cgi">
这将在Internet Explorer和Mozilla Firefox中运行。缺点是它不是XHTML标准。
您可以在输入中使用它。
例如
<input type=text name="test" autocomplete="off" />
<script language="javascript" type="text/javascript">
$(document).ready(function () {
try {
$("input[type='text']").each(
function(){
$(this).attr("autocomplete", "off");
});
}
catch (e) {
}
});
</script>
推荐文章
- 使伸缩项目正确浮动
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击