我正在使用 Wayfinder 和 Accordion 菜单的组合来驱动左栏菜单的行为。此菜单有两个级别,即:
<ul class="accordion">:
Menu 1
Sub-menu 1.1
Sub-menu 1.2
Sub-menu 1.3
Menu 2
Sub-menu 2.1
Sub-menu 2.2
Menu 3
Sub-menu 3.1
Sub-menu 3.2
Menu 4
Sub-menu 4.1
Sub-menu 4.2
还有以下标题菜单:
<ul class="nav"> (no sub-menus):
Menu 2
Menu 3
下面的代码处理左栏菜单(“手风琴”类)。我想扩展代码,因此从标题菜单(“nav”类)单击“Menu 2”与单击“Menu 2”(“accordion”类)具有相同的效果。即点击“Menu 2”(“nav”类)将扩展“Menu 2”和“accordion”类。
她的代码是:
<script type="text/javascript">
$(document).ready(function() {
// Store variables
var accordion_head = $('.accordion > li > a'),
accordion_body = $('.accordion li > .sub-menu'),
nav_head = $('.nav > li > a');
// Open the first tab on load
accordion_head.eq(2).addClass('active').next().slideDown('normal');
// Click function
accordion_head.on('click', function(event) {
// Disable header links
event.preventDefault();
// Show and hide the tabs on click
if ($(this).attr('class') != 'active'){
accordion_body.slideUp('normal');
$(this).next().stop(true,true).slideToggle('normal');
accordion_head.removeClass('active');
$(this).addClass('active');
}
else {
accordion_body.slideUp('normal');
accordion_head.removeClass('active');
}
});
nav_head.on('click', function(event) {
// Disable header links
event.preventDefault();
// Show and hide the 'accordion tabs' on click on the 'nav tabs'
<missing part>
});
});
</script>
非常感谢, LG