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

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

问题描述

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



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

 < html> 
< head>
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js>< / script>
< / head>
< body>
< div>
< input id =txtTesttype =text/>
< input type =buttononclick =$('#txtTest')。attr('disabled','disabled');值=设为禁用(jQuery)/>
< input type =buttononclick =document.getElementById('txtTest')。disabled = true; value =Set Disabled(js)/>
< input type =buttononclick =$('#txtTest')。removeAttr('disabled'); value =删除已禁用/>
< / div>
< / body>
< / html>

如果您动态禁用文本框,然后刷新页面,则文本框将保持禁用状态,而不是将其重置到其未禁用的原始状态。我已经在IE8和Chrome中尝试了这一点,那些行为和我所期望的一样,当我刷新的时候,将文本框重置为不被禁用。

另一个有趣的信息是如果输入是复选框而不是文本框,它仍然会执行相同的操作。 这是一个功能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天全站免登陆