如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?
当前回答
您可以在输入中使用它。
例如
<input type=text name="test" autocomplete="off" />
其他回答
在相关的或实际上,在完全相反的注释上-
“如果您是上述表单的用户,并希望重新启用自动完成功能,使用“记住密码”来自此bookmarklets的bookmarklet页它会删除页面上所有表单的所有autocomplete=“off”属性。保持好好战斗!"
对于React,您可以尝试将此代码放在表单下面或密码输入上面,或者放在电子邮件和密码输入之间
export const HackRemoveBrowsersAutofill = () => (
<>
<input type="email" autoComplete="new-password" style={ { display: 'none' } } />
<input type="password" autoComplete="new-password" style={ { display: 'none' } } />
</>
)
示例之一:
<input type="email"/>
<HackRemoveBrowsersAutofill/>
<input type="password"/>
定义输入的属性type=“text”和autocomplete=“off”足以为我关闭自动完成。
除了type=“password”之外,我尝试使用JavaScript钩住别人的建议中的onfocus/onfocuout事件来切换只读属性,效果很好,但当密码字段编辑开始为空时,自动完成密码再次出现。
我建议除了上述工作正常的解决方法之外,还可以使用JavaScript挂钩oninput事件来切换关于密码长度的类型属性。。
<input id="pwd1" type="text" autocomplete="off" oninput="sw(this)" readonly onfocus="a(this)" onfocusout="b(this)" />
<input id="pwd2" type="text" autocomplete="off" oninput="sw(this)" readonly onfocus="a(this)" onfocusout="b(this)" />
和JavaScript。。
function sw(e) {
e.setAttribute('type', (e.value.length > 0) ? 'password' : 'text');
}
function a(e) {
e.removeAttribute('readonly');
}
function b(e) {
e.setAttribute('readonly', 'readonly');
}
为了解决这个问题,我使用了一些CSS技巧和以下工作。
input {
text-security:disc;
-webkit-text-security:disc;
-mox-text-security:disc;
}
请阅读本文了解更多详情。
我的解决方案是使用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”
推荐文章
- 防止滚动条增加到Chrome页面的宽度
- 使用图像而不是单选按钮
- 我可以嵌套一个<按钮>元素内< >使用HTML5?
- 设置TextView文本从html格式的字符串资源在XML
- 为什么我的球(物体)没有缩小/消失?
- Twitter Bootstrap 3 Sticky Footer
- CSS在特定的“内联块”项之前/之后换行
- 很好的初学者教程socket.io?
- 点击下载Href图片链接
- HtmlSpecialChars在JavaScript中等价于什么?
- 我如何删除背景图像在css?
- 如何克服HTML表单嵌套的限制?
- 如何使Bootstrap 4卡在卡列相同的高度?
- 使用域集图例引导
- 音频停止功能