我有一个Joomla菜单,它使用jQuery将其变成手风琴菜单。我有手风琴功能,但我需要在访问者导航到特定页面时保持活动的子菜单项。我已经包含了jQuery代码和子菜单的HTML片段。 Joomla将一个“活动”类应用于HTML中的父元素和子元素元素,我想知道jQuery是否可以使用它来保持手风琴菜单打开。
(function($) {
$(document).ready(function() {
$('.accordion li.parent a').on('click', function() {
$('.accordion .first-level, .accordion .second-level').removeAttr('href');
var element = $(this).parent('li');
if (element.hasClass('open')) {
element.removeClass('open');
element.find('li').removeClass('open');
element.find('ul').slideUp();
} else {
element.addClass('open');
element.children('ul').slideDown();
element.siblings('li').children('ul').slideUp();
element.siblings('li').removeClass('open');
element.siblings('li').find('li').removeClass('open');
element.siblings('li').find('ul').slideUp();
}
});
});
})(jQuery);
<ul class="">
<li class="item-164 active deeper parent">
<a class="first-level" href="/projects/commercial" title="Commercial Projects" >
<span>Commercial</span>
</a>
<ul>
<li class="item-230 active deeper parent">
<a class="second-level" href="/projects/commercial/car-washes-and-gas-bars" title="Car Washes and Gas Bars" >
<span>Car Washes and Gas Bars</span>
</a>
<ul>
<li class="item-582 current active">
<a href="/projects/commercial/car-washes-and-gas-bars/squeeky-kleen-red-deer" >
<span>Squeeky Kleen Red Deer</span>
</a>
</li>
<li class="item-252">
<a href="/projects/commercial/car-washes-and-gas-bars/squeeky-kleen-sylvan-lake" title="Squeeky Kleen Sylvan Lake" >
<span>Squeeky Kleen Sylvan Lake</span>
</a>
</li>
<li class="item-253">
<a href="/projects/commercial/car-washes-and-gas-bars/squeeky-kleen-innisfail" title="Squeeky Kleen Innisfail" >
<span>Squeeky Kleen Innisfail</span>
</a>
</li>
<li class="item-251">
<a href="/projects/commercial/car-washes-and-gas-bars/scottys-esso" title="Scotty's Esso Drayton Valley" >
<span>Scotty's Esso</span>
</a>
</li>
<li class="item-250">
<a href="/projects/commercial/car-washes-and-gas-bars/big-bucket-car-wash" title="Big Bucket Car Wash" >
<span>Big Bucket Car Wash</span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>