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");
});
感謝
謝謝湯姆,另一個問題 – 2011-12-28 16:32:50
我試着添加類,它會將類添加到所有標題,一旦你點擊一個。我不認爲這種方法有效。 – 2011-12-28 17:19:54
用你猜的新代碼編輯你的問題,好像你沒有選擇'this'元素 – 2011-12-28 17:27:26