Firefox 的错误 - 刷新时不重置输入的禁用属性 [英] Bug With Firefox - Disabled Attribute of Input Not Resetting When Refreshing

查看:30
本文介绍了Firefox 的错误 - 刷新时不重置输入的禁用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我认为是 Firefox 的一个错误,我想知道这是否真的是一个错误,以及对此的任何解决方法.

如果您使用以下来源创建基本网页:

<头><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script><身体><div><input id="txtTest" type="text"/><input type="button" onclick="$('#txtTest').attr('disabled','disabled');"value="设置禁用 (jQuery)"/><input type="button" onclick="document.getElementById('txtTest').disabled = true;"value="设置禁用 (js)"/><input type="button" onclick="$('#txtTest').removeAttr('disabled');"值="删除禁用"/>

如果您disable textbox 动态然后刷新页面,textbox 将保持禁用状态,而不是重置回其原始状态未禁用.我已经在 IE8 和 Chrome 中尝试过这个,它们的行为符合我的预期,刷新时将 textbox 重置为未禁用.

另一个有趣的信息是,如果输入是 checkbox 而不是 textbox,它仍然会做同样的事情.

解决方案

这是 Firefox 的一个特性",它可以在页面刷新时记住表单输入值.要解决此问题,您只需在包含输入的表单上设置 autocomplete="off",或者直接设置为输入.

这会阻止自动完成工作并阻止浏览器记住输入字段的状态.

或者,您可以通过单击 CTRL+F5 来硬刷新".这将完全重置当前页面.

I've found what I believe to be a bug with Firefox and I'm wondering if this actually is a bug, as well as any workarounds for this.

If you create a basic webpage with the following source:

<html>
  <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
  </head>
  <body>
    <div>
      <input id="txtTest" type="text" />
      <input type="button" onclick="$('#txtTest').attr('disabled','disabled');" value="Set Disabled (jQuery)" />
      <input type="button" onclick="document.getElementById('txtTest').disabled = true;" value="Set Disabled (js)" />
      <input type="button" onclick="$('#txtTest').removeAttr('disabled');" value="Remove Disabled" />
    </div>
  </body>
</html>

If you disable the textbox dynamically and then refresh the page, the textbox will remain disabled instead of resetting back to its original state of not disabled. I've tried this in IE8 and Chrome and those behave as I would expect, resetting the textbox back to not disabled when I refresh.

Another interesting bit of information is that it still does the same thing if the input is a checkbox instead of a textbox.

解决方案

This is a "feature" of Firefox which remembers form input values across page refreshes. To fix this behavior, you simply set autocomplete="off" on the form containing the inputs, or just directly to the input.

This stops autocomplete from working and prevents the browser from remembering the state of input fields.

Alternatively, you can just "hard-refresh" by clicking CTRL+F5. This will completely reset the current page.

这篇关于Firefox 的错误 - 刷新时不重置输入的禁用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆