2012-03-27 110 views
-1

我有這部分功能:jQuery函數不工作的IE9

$jQ('.product-collateral .product-tabs li').each(function(index){ 
      $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); 
      if(index === 0) 
       $jQ(this).addClass('active'); 
     }); 

是否有任何理由爲什麼會這樣不使用Internet Explorer 9的工作?

我花了相當多的時間,現在試圖弄清楚,不知道。

非常感謝您的建議。

大教堂

- 對不起,這是HTML

<div class="product-collateral"> 
    <div class="tab"> 
     <h3 class="product_tabs_agenda">Tab 1</h3> 
    </div> 
    <div class="product-tabs-content" id="product_tabs_agenda_contents"> 
     <p>Tab1 Content</p> 
    </div> 
    <div class="tab"> 
     <h3 class="product_tabs_terms">Terms and Conditions</h3> 
    </div> 
    <div class="product-tabs-content" id="product_tabs_terms_contents"> 
     <p>Some terms and conditions</p> 
    </div> 
</div> 

,這是完整的Java功能。

< script type = "text/javascript" > $jQ('.product-collateral .tab h3').wrapAll('<ul class="product-tabs"></ul>').wrap('<li></li>'); 
$jQ('.product-collateral .product-tabs li').each(function(index) { 
    $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); 
    if (index == 0) $jQ(this).addClass('active'); 
}); 
//<![CDATA[ 
Varien.Tabs = Class.create(); 
Varien.Tabs.prototype = { 
    initialize: function(selector) { 
     var self = this; 
     $$(selector + ' h3').each(this.initTab.bind(this)); 
    }, 

    initTab: function(el) { 
     el.href = 'javascript:void(0)'; 
     if ($(el.parentNode).hasClassName('active')) { 
      this.showContent(el); 
     } 
     el.observe('click', this.showContent.bind(this, el)); 
    }, 

    showContent: function(a) { 
     var li = $(a.parentNode), 
      ul = $(li.parentNode); 
     ul.select('li', 'ol').each(function(el) { 
      var contents = $(el.id + '_contents'); 
      if (el == li) { 
       el.addClassName('active'); 
       contents.show(); 
      } else { 
       el.removeClassName('active'); 
       contents.hide(); 
      } 
     }); 
    } 
} 
new Varien.Tabs('.product-tabs'); 
//]]> 
< /script> 

對不起,我想這是我的無奈這個 「東西」

謝謝

+1

這是在其他瀏覽器中工作? – 2012-03-27 16:32:16

+2

「不起作用」是什麼意思?錯誤?意外的行爲?代碼的哪部分不起作用,或者沒有任何部分? – JJJ 2012-03-27 16:32:25

+0

你能否提供更多的代碼?像有問題的HTML,什麼具體是不工作... – Timmerz 2012-03-27 16:33:39

回答

1

http://api.jquery.com/jQuery.noConflict/

確保此預先定義。 $ jQ在您提供的代碼中沒有任何價值。

$jQ = jQuery.noConflict(); 

可能缺失。在調用別名之前,必須定義它。

+0

此外,請使用_或 - 始終在您的班級名稱中。 – 2012-03-27 17:52:14

+0

謝謝克里斯託弗,伊夫試過了。依然沒有。最奇怪的是,這個腳本在IE7和8模式下工作正常,但不是在9中。我很迷茫 – Dom 2012-03-28 08:44:54