Drupal 站点中的 jQuery addClass() 函数在 IE7 中不起作用
我正在尝试在 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() 问题,但没有一个问题看起来完全相同,解决方案也不是完全一致。
I am trying to use jQuery in the context of a Drupal site. The script works fine in other browsers including IE8, but in IE7 it partially breaks down.
Sample script code:
function showEducation() {
jQuery('#map-overlay').attr('class','').addClass('education');
jQuery('#map-legend-image').attr('src','/sites/all/images/map/legend-education.png');
}
... is used to how or hide an overlay on a map image, as well as change the src image for a map legend:
<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>
The legend updates when the appropriate area of the image map is clicked, but the overlay does not.
I have come across quite a few issues with addClass() in IE7, but none of the problems seemed quite the same, nor the solutions quite a propos.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
removeClass()从元素中删除所有类。
use
removeClass() remove all classes from element.
我从未见过 addClass() 在 IE7 中不起作用。你确定两者之间有问题吗?
您可以在不链接的情况下使用 addClass() 并看看它是否有效吗?如果这不起作用,您可以执行 .hide() 之类的操作来查看它是否隐藏您的元素吗?我试图确定 jQuery('#map-overlay') 在运行此代码时是否真正抓取了您的元素。
一般来说,如果没有示例,我们甚至无法验证这是 addClass() 和 IE7 的问题。如果上面的方法不能帮助你调试,你能提供一个jsfiddle链接,我在IE7上测试一下吗?
I've never seen addClass() not work in IE7. Are you certain there is an issue between the two?
Can you use addClass() without chaining and see if it works? If that does not work, can you do something like .hide() to see if it hides your element? I'm trying to determine if jQuery('#map-overlay') is actually grabbing your element at the time this code is run, or not.
Generally, without an example there is no way we can even verify that this is an issue with addClass() and IE7. If the above does not help you debug, can you provide a jsfiddle link, and I'll test it on IE7?