Firefox在重新加载时保留表单数据

And*_*eas 58 forms firefox caching

我在Firefox中的功能存在很大问题,它保留了用户在重新加载时填写的数据F5.如果我使用Ctrl+ F5表格被清除,这很好.我的问题是并非所有用户都知道这是强制输入清理所必须做的.是否有一种方法在html或响应头中告诉Firefox不保留表单中的数据?

And*_*eas 83

只需添加autocomplete="off"您的输入,您就可以解决问题.

<input type="text" autocomplete="off">
Run Code Online (Sandbox Code Playgroud)

jQuery在所有输入和textareas上解决这个问题

$('input,textarea').attr('autocomplete', 'off');
Run Code Online (Sandbox Code Playgroud)

  • 相反,您可以添加<form autocomplete ="off"> </ form来完全禁用表单的缓存 (28认同)
  • 不幸的是,这也会通过单击表单元素(它显示以前输入的值的下拉列表)来删除自动完成功能 (6认同)
  • 我研究了半天才明白这是firefox的问题。谢谢你的解决方案。 (2认同)

Dan*_* G. 14

您可以将属性添加到表单元素中,而不是遍历所有输入,如下所示:

<form method="post" autocomplete="off">...</form>

但是domReady上面提到的方法对我不起作用......


小智 6

我认为更简单快捷的方法是

$('input,textarea').attr('autocomplete', 'off');
Run Code Online (Sandbox Code Playgroud)


Fel*_*lix 6

如果您想保留浏览器的自动完成功能(请参阅其他有效答案),请尝试将 name 属性添加到表单并为其指定一个随机值。它对我有用:

<form id="my-form" name="<random-hash>">
...
</form>
Run Code Online (Sandbox Code Playgroud)


小智 5

我尝试了上面的缩短解决方案,但它没有清除我页面上选择框的值.

我最后稍微修改了它,现在无论类型如何,页面上的所有输入类型都被清除:

var allInputs = $(":input");
$(allInputs).attr('autocomplete', 'off');
Run Code Online (Sandbox Code Playgroud)

所以为了使这个运行onload我只是把它放在ready()方法中:

$(document).ready(function () {
    var allInputs = $(":input");
    $(allInputs).attr('autocomplete', 'off');
});
Run Code Online (Sandbox Code Playgroud)


www*_*139 5

/*reset form elements (firefox saves it)*/

function resetElements()
{
     var inputs = document.querySelectorAll('input[type=text]');
     //you get the idea.....you can retrieve all inputs by tag name input
     for(var i = 0; i < inputs.length; i++) {
         document.getElementsByTagName('input')[i].value = "";
     }
     var textareas = document.getElementsByTagName('textarea');
     for(var i = 0; i < textareas.length; i++) {
         document.getElementsByTagName('textarea')[i].value = "";
     }
}
Run Code Online (Sandbox Code Playgroud)

调用此函数onload.

  • 我喜欢的Javascript解决方案是输入建议继续工作,只删除输入字段值,而`autocomplete ="off"`也禁用建议. (2认同)