开发者

jquery accordion menu - link problem

I'm using this http://www.i-marco.nl/weblog/jquery-accordion-menu/ accordion menu.

Problem is, is that the main-menu links only work to expand the sub-menu, but don't function as links themselves. I want the main-menu links to go to the link and (i set the expand class via a php script) unfold the sub-menu.

Here's the code:

html (example):

<span class="acc_menu"> 
<ul class="menu"> 
<li class="expand"> 
<a href="/a_page.html">A page</a> 
<ul class="menu nestedmenu开发者_Python百科 acitem"> 
<li><a href="/other_page.html">Other page</a></li> 
<li><a href="/other_page2.html">Other page 2</a></li> 
<li><a href="/other_page3.html">Other page 3</a></li> 
</ul> 
</li>
</ul>

jquery:

jQuery.fn.initMenu = function() {
return this.each(function(){
    var theMenu = $(this).get(0);
    $('.acitem', this).hide();
    $('li.expand > .acitem', this).show();
    $('li.expand > .acitem', this).prev().addClass('active');
    $('li a', this).click(
        function(e) {
            e.stopImmediatePropagation();
            var theElement = $(this).next();
            var parent = this.parentNode.parentNode;
            if($(parent).hasClass('noaccordion')) {
                if(theElement[0] === undefined) {
                    window.location.href = this.href;
                }
                $(theElement).slideToggle('normal', function() {
                    if ($(this).is(':visible')) {
                        $(this).prev().addClass('active');
                    }
                    else {
                        $(this).prev().removeClass('active');
                    }    
                });
                return false;
            }
            else {
                if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                    if($(parent).hasClass('collapsible')) {
                        $('.acitem:visible', parent).first().slideUp('normal', 
                        function() {
                            $(this).prev().removeClass('active');
                        }
                    );
                    return false;  
                }
                return false;
            }
            if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                $('.acitem:visible', parent).first().slideUp('normal', function() {
                    $(this).prev().removeClass('active');
                });
                theElement.slideDown('normal', function() {
                    $(this).prev().addClass('active');
                });
                return false;
            }
        }
    }
);
});
};

$(document).ready(function() {
    $('.menu').initMenu();
}); // enter code here


Just add target="_blank" to your parent link, and remove the return false;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜