嗨,我有一个手风琴菜单,一切正常,除非某个部分没有子类别,我需要链接到页面而不是尝试打开不存在的子菜单。
如何在此代码中实现这一点?
$.noConflict();
$(document).ready(function() {
// Store variables
var accordion_head = $('ul.accordion > li > a.item'),
accordion_body = $('ul.accordion li > ul.sub-menu');
// 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');
}
});
});
HTML....
<div class="Block CategoryList Moveable" id="SideCategoryList">
<div class="BlockContent" id="dropDowns">
<ul class="accordion">
<li><a href="http://site-link.co.uk" >Main Category 1</a>
<ul class="sub-menu"> <li><a href="http://site-link.co.uk" class="item">item 1</a>
</li> <li ><a href="http://site-link.co.uk" class="item">item 2</a>
</li> <li ><a href="http://site-link.co.uk" class="item" >item 3</a>
</li> <li ><a href="http://site-link.co.uk" class="item">item 4</a>
</li></ul>
</li> <li ><a href="http://site-link.co.uk" class="item">Main Category 2</a>
</li> <li ><a href="http://site-link.co.uk" class="item">Main Category 3</a>
</li>
</ul>