【问题标题】:jQuery addClass() function in a Drupal site isn't working in IE7Drupal 站点中的 jQuery addClass() 函数在 IE7 中不起作用
【发布时间】:2011-10-03 22:47:25
【问题描述】:

我正在尝试在 Drupal 站点的上下文中使用 jQuery。该脚本在包括 IE8 在内的其他浏览器中运行良好,但在 IE7 中它会部分崩溃。

示例脚本代码:

function showEducation() {
   jQuery('#map-overlay').attr('class','').addClass('education');
   jQuery('#map-legend-image').attr('src','/sites/all/images/map/legend-education.png');
}

... 用于如何或隐藏地图图像上的叠加层,以及更改地图图例的 src 图像:

<div id="map">
  <img id="map_image" src="[map path]" />
  <div id="map-overlay"></div>
  <div id="map-legend">
    <img src="[legend path]" usemap="#map-legend-imageMap" id="map-legend-image" />
    <map name="map-legend-imageMap" id="map-legend-imageMap">
      <area shape="rect" coords="12,11,271,66" href="javascript:showEducation()" />
    </map>
  </div>
</div>

当点击图像地图的适当区域时,图例会更新,但覆盖不会。

我在 IE7 中遇到了很多关于 addClass() 的问题,但似乎没有一个问题完全一样,解决方案也不是一个建议。

【问题讨论】:

  • removeClass()交换attr('class', '')
  • 你用的是什么版本的jQuery?
  • removeClass() 没有任何区别。至于 jQuery 的哪个版本,它看起来是 Drupal 7 附带的 1.4.4 版本。

标签: jquery drupal internet-explorer-7 drupal-7 addclass


【解决方案1】:
jQuery('#map-overlay').attr('class','').addClass('education');//instead of this

使用

jQuery('#map-overlay').removeClass().addClass('education');

removeClass() 从元素中删除所有类。

【讨论】:

    【解决方案2】:

    我从未见过 addClass() 在 IE7 中不起作用。你确定这两者之间有问题吗?

    你可以使用 addClass() 而不使用链接,看看它是否有效?如果这不起作用,您可以执行 .hide() 之类的操作来查看它是否隐藏了您的元素吗?我正在尝试确定 jQuery('#map-overlay') 在运行此代码时是否真的在抓取您的元素。

    通常,如果没有示例,我们甚至无法验证这是 addClass() 和 IE7 的问题。如果以上不能帮你调试,能否提供一个jsfiddle链接,我在IE7上测试一下?

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多