jquery - 打开多个 Accordion 选项卡

标签 jquery jquery-ui css accordion

我已经实现了 Accordion 内容选项卡。目前它允许一次打开一个菜单。我还需要同时打开其他选项卡。

这是我的代码

(function(jQuery){
     jQuery.fn.extend({  
         accordion: function() {       
            return this.each(function() {

                var $ul = $(this);

                if($ul.data('accordiated'))
                    return false;

                $.each($ul.find('ul, li>div'), function(){
                    $(this).data('accordiated', true);
                    $(this).hide();
                });

                $.each($ul.find('a'), function(){
                    $(this).click(function(e){
                        activate(this);
                        return void(0);
                    });
                });

                var active = (location.hash)?$(this).find('a[href=' + location.hash + ']')[0]:'';

                if(active){
                    activate(active, 'toggle');
                    $(active).parents().show();
                }

                function activate(el,effect){
                    $(el).parent('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');
                    $(el).siblings('ul, div').slideToggle("slow");((!effect)?'fast':null);
                }

            });
        } 
    }); 
        $('ul').accordion();
             $(".info").find("a").click(function(){
              var trid = $(this).parent().attr("idcust");                
              var trdata = $(this).parent().attr("custdata");
            // Hide all content divs and show only the one related to the click
             $("#"+trid).show().children().not(trdata).hide();
            $(trdata).toggle();
        });
})(jQuery);

DEMO HERE

最佳答案

首先我想说 CSS 和 JS 中有很多垃圾代码。像这样写:

JS

$('.accordion a').click(function(){
    $('.accordion div').slideToggle("slow");;
});

CSS

.accordion div {  background: #fff;overflow:hidden;display:none;}

检查这个http://jsfiddle.net/RVJQN/1/

关于jquery - 打开多个 Accordion 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14724327/

相关文章:

javascript - 带有自定义参数的Ajax请求

javascript - 如何在 Angular 2 中使用 jQuery UI

html - Angular 组件倾斜的背景

HTML 和 CSS,无法让文本正确地 float 在图像旁边

jquery - 如何自动打开 "accordion"到第一个选择?

javascript - 在 jQuery 中显示选择下拉列表?

javascript - 如何将复选框的值保存到 session 存储并在下一页检索它们

JQuery 用户界面 : Part of a negative margins image disappears if I animate it

jquery-ui - 未捕获的类型错误 : Object[object Object ] has no method 'tabs'

css - 白色边框没有出现