【问题标题】:Weird bug in Firefox using disabled="disabled"Firefox 中使用 disabled="disabled" 的奇怪错误
【发布时间】:2014-05-05 21:31:19
【问题描述】:

我正在研究 ff 中的一个错误:

参见http://nocturne.wmw.cc/bugff.html(在 jsfiddle 中不可重现 - 太糟糕了)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  </head>
<body>
 <button disabled="disabled">sdf</button>
 <script>
  jQuery(function(){
    if(!jQuery('button').is(':disabled'))
      alert('Is not disabled!');
    jQuery('button').removeAttr('disabled');
  });
</script>
</body>
</html>

现在的问题:

  1. 如果我是第一次加载,一切正常。
  2. 如果我使用 Ctrl+r 重新加载页面,alert() 会显示错误消息。
  3. 如果我使用 Ctrl+Shift+r 重新加载,则不会出现该错误。

我确实使用 Microsoft® Windows® 7。 至少在 FF28、FF29 可重现。

如何解决?

【问题讨论】:

  • 那么...你有问题吗?
  • @PeterRader,别粗鲁,我很清楚我的建议,jQuery('button').prop('disabled') == truejQuery('button').is(':disabled') 将为您提供相同的结果
  • @ekans jQuery( function() {..} )$(document).ready( function() {..} ) 相同。
  • 您使用的是这个确切的代码吗?因为它缺少结束脚本标记
  • 这是一个真正的错误。我同意@PeterRader 为什么是-1,为什么离题?还有一件事彼得可以把你的脚本放在头部分

标签: javascript jquery html firefox


【解决方案1】:

问题似乎与为表单元素存储用户输入的机制相同,按钮的状态已被缓存。

可能的解决方案(见:How can I stop Firefox from caching the contents of a textarea on localhost?):

<button disabled="disabled" autocomplete="off">sdf</button>

http://jsfiddle.net/doktormolle/4ZLd9/show/

【讨论】:

【解决方案2】:

试试 disabled 而不是 disabled = "disabled"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  <body>
    <button disabled>sdf</button>
    <script>
      jQuery(function(){
        if(!jQuery('button').is(':disabled'))
         alert('Is not disabled!');
       jQuery('button').removeAttr('disabled');
      });
     </script>
  </body>
</html>

【讨论】:

  • 本地为我工作,您可以复制源代码并在本地尝试。如果您在 firebug 中检查代码,您可以看到没有 disabled 属性,如果在 firebug 中编辑代码,它将禁用按钮
  • 你用的是什么ff版本?
  • 您是否停用了 chronik 或其他什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
  • 2011-05-07
  • 2011-08-28
  • 2015-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多