如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?
当前回答
<input autocomplete="off" aria-invalid="false" aria-haspopup="false" spellcheck="false" />
我发现它在所有浏览器上都适用。当我只使用自动完成时,它不起作用,除非我组合了您看到的所有属性。此外,我还从谷歌表单输入字段获得了解决方案
其他回答
我通过添加两个假输入并赋予它们绝对位置来阻止Chrome 66自动填充:
<form style="position: relative">
<div style="position: absolute; top: -999px; left: -999px;">
<input name="username" type="text" />
<input name="password" type="password" />
</div>
<input name="username" type="text" />
<input name="password" type="password" />
起初,我尝试添加display:none;但Chrome忽略了这些输入,并自动填充可见的输入。
我的解决方案是使用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”
这就是我们所说的文本框自动完成。
我们可以通过两种方式禁用文本框的自动完成:
按浏览器标签按代码要在浏览器中禁用,请转到设置
转到“高级设置”,取消选中复选框,然后单击“还原”。
如果要禁用编码标签,可以执行以下操作-
使用AutoCompleteType=“禁用”:
<asp:TextBox runat="server" ID="txt_userid" AutoCompleteType="Disabled"></asp:TextBox>
通过设置表单自动完成=“off”:
<asp:TextBox runat="server" ID="txt_userid" autocomplete="off"></asp:TextBox>
通过设置表单自动完成=“off”:
<form id="form1" runat="server" autocomplete="off">
// Your content
</form>
通过使用.cs页面中的代码:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
txt_userid.Attributes.Add("autocomplete", "off");
}
}
通过使用jQuery
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#txt_userid').attr('autocomplete', 'off');
});
</script>
为了解决这个问题,我使用了一些CSS技巧和以下工作。
input {
text-security:disc;
-webkit-text-security:disc;
-mox-text-security:disc;
}
请阅读本文了解更多详情。
我刚刚遇到了这个问题,并尝试了几次失败,但这一次对我有效(在MDN上找到):
在某些情况下,浏览器将继续建议自动完成值即使autocomplete属性设置为off。这是意外的对于开发人员来说,这种行为可能非常令人困惑。真正的诀窍强制无完成是将随机字符串分配给属性像这样:
autocomplete="nope"
推荐文章
- 使伸缩项目正确浮动
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击