2011-10-03 34 views
2

我想在Drupal站點的上下文中使用jQuery。該腳本在其他瀏覽器(包括IE8)中運行正常,但在IE7中它部分崩潰。在Drupal站點中的jQuery addClass()函數在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()的問題,但沒有一個問題看起來完全相同,也沒有提出相應的解決方案。

+2

用'removeClass()'交換'attr('class','')'。 – alex

+0

您使用的是什麼版本的jQuery? –

+0

removeClass()沒有什麼區別。至於哪個版本的jQuery,它看起來是1.4.4,這是Drupal 7附帶的版本。 –

回答

0
jQuery('#map-overlay').attr('class','').addClass('education');//instead of this 

使用

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

removeClass()從元件除去的所有類。

0

我從來沒見過addClass()在IE7中不起作用。你確定兩者之間有問題嗎?

您可以使用addClass()而無需鏈接並查看它是否有效?如果這不起作用,你可以做一些類似.hide()的東西來看看它是否隱藏了你的元素?我試圖確定jQuery('#map-overlay')是否實際上在代碼運行時抓住你的元素,或者不是。

通常,沒有一個例子,我們甚至無法驗證這是addClass()和IE7的問題。如果上述不能幫助你調試,你能提供一個jsfiddle鏈接,我會在IE7上測試它嗎?