禁用 Firefox 的自动填充 [英] Disable Firefox's Auto-fill
问题描述
是否可以在不禁用自动完成的情况下禁用 Firefox 的自动填充功能?
Is it possible to disable Firefox's auto-fill feature without disabling auto-complete?
我知道我可以做到:
autocomplete="off"
但我不想禁用自动完成,只想禁用自动填充.
But I don't want to disable auto-complete, just the auto-fill.
Firefox 正在填充我们一些本应为空的隐藏字段
这主要是用户刷新页面时出现的问题.使用预刷新中的值重新填充表单字段.这个问题的一个例子是老式的占位符.我们用一个值填充该字段,并在提交时将其删除.该值在刷新时重新填充,我们不知道它是占位符还是使用值.
This is mostly a problem when the user refreshes the page. The form fields are re-populated with values from pre-refresh. An example of this being a problem is old-school place-holder. Where we populate the field with a value, and remove it on submit. The value is re-populated on refresh and we don't know if it's the place-holder or use value.
推荐答案
如果问题是 FF 在用户刷新时填充字段,这其实是 Firefox 的一个功能,试图在用户不小心的情况下帮助用户刷新,这样他们就不会丢失他们输入的任何内容.我认为你不能用 HTML 覆盖它.您可以使用 JavaScript 在页面加载时清除/重置所有相关的表单值.如果表单上的 form.reset() 不起作用,您将必须遍历表单元素并像这样清除它们:
If the problem is that FF is populating the fields when the user refreshes, this is actually a feature of Firefox to try to help the user in the case of accidental refresh so they don't lose whatever they have typed. I don't think you can override this with the HTML. You could use JavaScript to clear/reset all the relevant form values on page load. If a form.reset() on the form doesn't work, you will have to iterate over the form elements and clear them like this:
for (i = 0; i < frm_elements.length; i++)
{
field_type = frm_elements[i].type.toLowerCase();
switch (field_type)
{
case "text":
case "password":
case "textarea":
case "hidden":
frm_elements[i].value = "";
break;
case "radio":
case "checkbox":
if (frm_elements[i].checked)
{
frm_elements[i].checked = false;
}
break;
case "select-one":
case "select-multi":
frm_elements[i].selectedIndex = -1;
break;
default:
break;
}
}
这篇关于禁用 Firefox 的自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!