【问题标题】:jQuery Code doesn't work in IE9jQuery 代码在 IE9 中不起作用
【发布时间】:2014-11-12 15:52:25
【问题描述】:
$screenWidth = $(document).width();
  if ($screenWidth < 980) {
    $('#show-menu').removeAttr('checked')
  }

此代码在 IE9 中不起作用。也许jQuery甚至没有加载? https://alphafotograf.de/ 如果选中该复选框,则左侧的菜单将可见。如果屏幕宽度低于 980 像素,则不会选中复选框并且菜单不可见。 请忽略控制台错误,它们与此无关。

【问题讨论】:

  • 您需要在问题中提供更多内容,但答案无论如何都隐藏在页面中,所以 +1 以减轻投票的痛苦:)

标签: javascript jquery html internet-explorer internet-explorer-9


【解决方案1】:

尝试使用

$('#show-menu').prop('checked',false)

而不是

$('#show-menu').removeAttr('checked')

您应该始终将prop 用于checked 属性(跨浏览器保持一致)。

当我在 Chrome 的 F12 工具中运行该网站时,我看到两个错误,在它到达这行代码之前停止执行:

第 107 行:Uncaught SyntaxError: Unexpected token ILLEGAL

$('iframe').load( function() { $('iframe').contents().find("head") .append($("

第 57 行:Uncaught TypeError: undefined is not a function

jQuery('.hasTooltip').tooltip({"html": true,"container": "body"});

【讨论】:

  • 我注意到代码不在 DOM 就绪处理程序中。如果你在代码中的那个位置alert($screenWidth),你会得到什么?
  • 我还注意到我在页面上出现错误,甚至在它到达该行之前 :)
  • 检查您的控制台...以及上面的修订。我无法断点所需的行,因为 is 前面有一个错误。
  • 当我删除脚本时,它仍然无法在 ie9 中运行。所以 ie 似乎没有将checked="checked" 理解为复选框的属性。
  • 好的,我删除了 iframe 脚本。它现在可以工作了,非常感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-27
  • 1970-01-01
相关资源
最近更新 更多