jQuery Accordion的基本问题

Basic issue with jQuery Accordion

本文关键字:问题 Accordion jQuery      更新时间:2023-09-26

我使用jQuery手风琴作为侧边栏导航。目前我有两个链接,都有"孩子"在他们下面。

这是我的jsFiddle: http://jsfiddle.net/6Eh8C/

你会注意到,当你点击"关于我们",画廊关闭。这不应该发生。只有当我点击'Gallery'时,Gallery才会关闭。

如何解决这个问题?

这是我的jQuery:
jQuery(function($) {
        $('#accordion > li > a').click(function (e) {
            if ($(this).next('ul').length == 0) {
                // link is for navigation, do not set up accordion here
                return;
            }
            // link is for accordion pane
            //remove all the "Over" class, so that the arrow reset to default
            $('#accordion > li > a').not(this).each(function () {
                if ($(this).attr('rel')!='') {
                    $(this).removeClass($(this).attr('rel') + 'Over');
                }
                $(this).siblings('ul').slideUp("slow");
            });
            //showhide the selected submenu
            $(this).siblings('ul').slideToggle("slow");
            //addremove Over class, so that the arrow pointing downup
            $(this).toggleClass($(this).attr('rel') + 'Over');
            e.preventDefault();
        });     
        $('.slides_item').children('div').css('background','#ededed')
    });

非常感谢您的指点:-)

我想你只是想删除一行:

$('#accordion > li > a').not(this).each(function () {
    if ($(this).attr('rel')!='') {
        $(this).removeClass($(this).attr('rel') + 'Over');
    }
    // Remove this line, you don't want to slide up other uls.
    // $(this).siblings('ul').slideUp("slow");
});

例子: http://jsfiddle.net/6Eh8C/1/