为什么这段代码不能一直工作?
我有这个 javascript 代码:
if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
{
$(window).load(function()
{
$('input:-webkit-autofill').each(function()
{
var text = $(this).val();
var name = $(this).attr('name');
$(this).after(this.outerHTML).remove();
$('input[name=' + name + ']').val(text);
});
});
}
它旨在删除输入中 webkit 自动填充背景颜色的背景颜色。
但是,它仅有时工作,当我单击输入或在页面加载的大约同一时间执行 jQuery 异步函数的按钮时,它不起作用。
这段代码有什么问题导致它有时不工作,但有时工作?我必须适应什么?
这就是我正在做的: 如何您是否在网络表单字段/输入标记上禁用浏览器自动完成功能?
但我想保持自动完成功能,同时删除背景。我需要这个,因为背景覆盖了我的文本输入中的背景图像,所以你看不到它。
I have this javascript code:
if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
{
$(window).load(function()
{
$('input:-webkit-autofill').each(function()
{
var text = $(this).val();
var name = $(this).attr('name');
$(this).after(this.outerHTML).remove();
$('input[name=' + name + ']').val(text);
});
});
}
It is designed to remove the background color of the webkit autofill background color in inputs.
However, it only works sometimes and doesn't work when I click on an input, or a button that executes jQuery async functions at around the same time that the page loads.
What is wrong with this code that makes it not work sometimes, but work other times? What must I adapt?
This is what I am doing: How do you disable browser Autocomplete on web form field / input tag?
But I want to keep autocomplete on, while removing the background. I need this, as the background goes over a background image in my text input, so you can't see it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是你正在尝试的吗? 如何在网络上禁用浏览器自动完成功能表单字段/输入标签?
如果不是--
您能否确认所有元素都已被选择,并且问题出在浏览器自动填充的时间上?如果您使用更常见的 $.ready 来代替,会发生什么?
Is this what you're attempting? How do you disable browser Autocomplete on web form field / input tag?
if not--
Can you confirm that all the elements are being selected, and that the problem lies in the timing of the browser's autofill? What happens if you use the more common $.ready instead?