2011-12-27 98 views
2

我是jquery的新手。我在jQuery導航上工作了這麼多天,現在工作正常,但我想添加更多的功能。Jquery手風琴多級導航

我有三級嵌套的手風琴導航,我想讓用戶知道他們在哪一節上應用背景顏色,現在我只能將背景顏色放到最後一級,如何我也可以將不同的背景顏色應用於父級別。

<div id="accordion"> 
    <h3><a>Link One - First Level</a></h3> 
    <div class="accordionSecond">  
     <h6><a href="#">Second Level</a></h6> 
     <div class="accordionLink"> 
     <a href="1.html">1.html</a> 
     <a href="2.html">2.html</a> 
     <a href="3.html">3.html</a> 
     <a href="4.html">4.html</a> 
     </div> 
    </div> 

    <h3><a>Link Two - First Level</a></h3> 
    <div class="accordionSecond">  
     <h6><a href="#">Second Level</a></h6> 
     <div class="accordionLink"> 
     <a href="1.html">1.html</a> 
     <a href="2.html">2.html</a> 
     <a href="3.html">3.html</a> 
     <a href="4.html">4.html</a> 
     </div> 
    </div>  

</div> 

這裏是CSS行的背景顏色適用於他們對

.accordionSecond .activeLink { background: #ccc; color:#000!important; } 

jQuery的頭部代碼的水平在這裏

<script> 
    $(document).ready(function() { 
    $("#accordion").accordion({active: true, collapsible: true, header: "h3", autoHeight: false, navigation: true, event: 'mouseup'}); 
    $(".accordionSecond").accordion({active: true, collapsible: true, header: "h6", autoHeight: false, navigation: true,event: 'mouseup'}); 
    }); 
    </script> 

<script type="text/javascript"> 
$(document).ready(function(){ 
    var path = location.pathname; 
     jQuery("a[href$='" + path + "']").addClass("activeLink"); 
}); 

感謝

回答

0

喜花看看click api,它也演示了添加一個類(可以說你添加了一個'acti ve''級別的頭部你點擊)和你請求的行爲的類型。很明顯,你將不得不擴展這個演示,但應該有很多在線添加和刪除類的例子。

+0

謝謝湯姆,另一個問題 – 2011-12-28 16:32:50

+0

我試着添加類,它會將類添加到所有標題,一旦你點擊一個。我不認爲這種方法有效。 – 2011-12-28 17:19:54

+0

用你猜的新代碼編輯你的問題,好像你沒有選擇'this'元素 – 2011-12-28 17:27:26