【发布时间】:2016-08-31 00:56:25
【问题描述】:
我遇到了 Chrome 自动填充字段的问题,其中 Chrome 忽略了“autocmplete="false|off|others"”。我还尝试了隐藏的假字段,this、this 等等。它似乎不起作用。字段变为黄色并包含密码,为此我决定使用以下 CSS 规则:
input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill
{
-webkit-box-shadow: 0 0 0 1000px white inset !important;
}
使用 javascript:
$(window).load(function() {
console.log('Inside JQuery Window.Load...');
if(document.querySelector("input:-webkit-autofill")!= null) {
document.querySelector("input:-webkit-autofill").value = "";
}
console.log('Autofill value(Before Alert): ' + document.querySelector("input:-webkit-autofill"));
alert('An alert...');
if(document.querySelector("input:-webkit-autofill")!= null) {
document.querySelector("input:-webkit-autofill").value = "";
}
console.log('Autofill value(After Alert): ' + document.querySelector("input:-webkit-autofill"));
});
手动覆盖该字段。
这是上述脚本的日志输出:
Inside JQuery Window.Load...
XXX:1324 Autofill value(Before Alert): null
XXX:1329 Autofill value(After Alert): [object HTMLInputElement]
当它在调试模式下运行时:
Inside JQuery Window.Load...
XXX:1324 Autofill value(Before Alert): [object HTMLInputElement]
XXX:1329 Autofill value(After Alert): [object HTMLInputElement]
我尝试了以下排列:
$('input:-webkit-autofill').each(function(){...});
window.document.querySelector("input:-webkit-autofill");
<body onload="chromeCheckAutofill();" />
<script>
function checkAutofill() {
if(document.querySelector("input:-webkit-autofill")!= null) {
document.querySelector("input:-webkit-autofill").value = "";
}
}
</script>
这是有问题的字段:
<input name="MY_REFNO" id="MY_REFNO" style="WIDTH: 180px" maxlength="16" onkeypress="upperAlphanumberHandler(event)" onblur="upperAlphanumberChecker('MY_REFNO')" value="" autocomplete="off">
我做错了什么? 我该如何解决这个问题...
【问题讨论】:
-
可以添加一些 HTML 代码 sn-p 吗?
-
没有
<form autocomplete="off" ...></form>工作? -
您正在尝试使用 HTML 和 JS 来操纵 Chrome 的工作方式?您是否也打算为 IE/Edge/Safari/Opera 实施单独的解决方案来覆盖它们的自动填充功能?
-
我不必... Firefox 和 IE 在 autocomplete='off' 方面没有问题
标签: javascript jquery google-chrome onload autofill