嵌套Bootstrap 3手风琴无法正常工作

时间:2014-09-26 09:56:04

标签: jquery twitter-bootstrap accordion

我努力让二级手风琴扩大。有任何想法吗?

第一级扩展,但内部级别不扩展。我想我的标记可能太多了!但我找不到一个很好的例子。

请参阅http://jsfiddle.net/pzh20/fcjq2dd0/

<div class="panel-group" id="accordion" style="width:80%; margin:0 auto;">
<div class='panel panel-primary'>
    <div class='panel-heading'>
        <h4 class='panel-title'><a data-toggle='collapse' data-parent='#accordion' href='#week52014'><span class='fyw'>5</span><span class='ztdate'>2014-2015</span><span class='total'>£weektotal</span></a></h4>
    </div>
    <div id='week52014' class='panel-collapse collapse'>
        <div class='panel-body'>
            <div class='panel panel-primary'>
                <div class='panel-heading'>
                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#week52014' href='holacg52014'><span class='bu'>New Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£buweektotal</span></a></h4>
                </div>
                <div id='holacg52014' class='panel-collapse collapse'>
                    <div class='panel-body'>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg52014' href='#holacg3152014'><span class='bu'>New Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='holacg3152014' class='panel-collapse collapse'>
                                <div class='panel-body'>
                                    <p><span class='depart'>Food Retail</span><span class='total'>£143.01</span></p>
                                </div>
                            </div>
                        </div>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg52014' href='#holacg3052014'><span class='bu'>New Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='holacg3052014' class='panel-collapse collapse '>
                                <div class='panel-body'>
                                    <p><span class='depart'>Paella</span><span class='total'>£436.25</span></p>
                                </div>
                            </div>
                        </div>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg52014' href='#holacg2952014'><span class='bu'>New Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='holacg2952014' class='panel-collapse collapse '>
                                <div class='panel-body'>
                                    <p><span class='depart'>Food Retail</span><span class='total'>£36.60</span></p>
                                </div>
                            </div>
                        </div>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg52014' href='#holacg2852014'><span class='bu'>New Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='holacg2852014' class='panel-collapse collapse '>
                                <div class='panel-body'>
                                    <p><span class='depart'>Paella</span><span class='total'>£330.42</span></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class='panel panel-primary'>
                <div class='panel-heading'>
                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#week52014' href='lmdqbm52014'><span class='bu'>Old Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£buweektotal</span></a></h4>
                </div>
                <div id='lmdqbm52014' class='panel-collapse collapse'>
                    <div class='panel-body'>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm52014' href='#lmdqbm3152014'><span class='bu'>Old Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='lmdqbm3152014' class='panel-collapse collapse'>
                                <div class='panel-body'>
                                    <p><span class='depart'>Food Retail</span><span class='total'>£143.01</span></p>
                                </div>
                            </div>
                        </div>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm52014' href='#lmdqbm3052014'><span class='bu'>Old Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='lmdqbm3052014' class='panel-collapse collapse '>
                                <div class='panel-body'>
                                    <p><span class='depart'>Paella</span><span class='total'>£436.25</span></p>
                                </div>
                            </div>
                        </div>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm52014' href='#lmdqbm2952014'><span class='bu'>Old Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='lmdqbm2952014' class='panel-collapse collapse '>
                                <div class='panel-body'>
                                    <p><span class='depart'>Food Retail</span><span class='total'>£36.60</span></p>
                                </div>
                            </div>
                        </div>
                        <div class='panel panel-primary'>
                            <div class='panel-heading'>
                                <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm52014' href='#lmdqbm2852014'><span class='bu'>Old Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                            </div>
                            <div id='lmdqbm2852014' class='panel-collapse collapse '>
                                <div class='panel-body'>
                                    <p><span class='depart'>Paella</span><span class='total'>£330.42</span></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class='panel panel-primary'>
        <div class='panel-heading'>
            <h4 class='panel-title'><a data-toggle='collapse' data-parent='#accordion' href='#week42014'><span class='fyw'>4</span><span class='ztdate'>2014-2015</span><span class='total'>£weektotal</span></a></h4>
        </div>
        <div id='week42014' class='panel-collapse collapse'>
            <div class='panel-body'>
                <div class='panel panel-primary'>
                    <div class='panel-heading'>
                        <h4 class='panel-title'><a data-toggle='collapse' data-parent='#week42014' href='holacg42014'><span class='bu'>New Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£buweektotal</span></a></h4>
                    </div>
                    <div id='holacg42014' class='panel-collapse collapse'>
                        <div class='panel-body'>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg42014' href='#holacg3142014'><span class='bu'>New Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='holacg3142014' class='panel-collapse collapse'>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Food Retail</span><span class='total'>£143.01</span></p>
                                    </div>
                                </div>
                            </div>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg42014' href='#holacg3042014'><span class='bu'>New Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='holacg3042014' class='panel-collapse collapse '>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Paella</span><span class='total'>£436.25</span></p>
                                    </div>
                                </div>
                            </div>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg42014' href='#holacg2942014'><span class='bu'>New Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='holacg2942014' class='panel-collapse collapse '>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Food Retail</span><span class='total'>£36.60</span></p>
                                    </div>
                                </div>
                            </div>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#holacg42014' href='#holacg2842014'><span class='bu'>New Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='holacg2842014' class='panel-collapse collapse '>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Paella</span><span class='total'>£330.42</span></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class='panel panel-primary'>
                    <div class='panel-heading'>
                        <h4 class='panel-title'><a data-toggle='collapse' data-parent='#week42014' href='lmdqbm42014'><span class='bu'>Old Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£buweektotal</span></a></h4>
                    </div>
                    <div id='lmdqbm42014' class='panel-collapse collapse'>
                        <div class='panel-body'>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm42014' href='#lmdqbm3142014'><span class='bu'>Old Market</span><span class='ztdate'>31/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='lmdqbm3142014' class='panel-collapse collapse'>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Food Retail</span><span class='total'>£143.01</span></p>
                                    </div>
                                </div>
                            </div>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm42014' href='#lmdqbm3042014'><span class='bu'>Old Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='lmdqbm3042014' class='panel-collapse collapse '>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Paella</span><span class='total'>£436.25</span></p>
                                    </div>
                                </div>
                            </div>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm42014' href='#lmdqbm2942014'><span class='bu'>Old Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='lmdqbm2942014' class='panel-collapse collapse '>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Food Retail</span><span class='total'>£36.60</span></p>
                                    </div>
                                </div>
                            </div>
                            <div class='panel panel-primary'>
                                <div class='panel-heading'>
                                    <h4 class='panel-title'><a data-toggle='collapse' data-parent='#lmdqbm42014' href='#lmdqbm2842014'><span class='bu'>Old Market</span><span class='ztdate'>30/08/2014</span><span class='total'>£budaytotal</span></a></h4>
                                </div>
                                <div id='lmdqbm2842014' class='panel-collapse collapse '>
                                    <div class='panel-body'>
                                        <p><span class='depart'>Paella</span><span class='total'>£330.42</span></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

此致 皮特

1 个答案:

答案 0 :(得分:0)

下面是嵌套手风琴的答案。希望它有效。 工作jsFiddle example

HTML:

<div class="panel-group" id="accordion">
          <div class="panel panel-default">
            <div class="panel-heading" id="head1">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion">
                  Tab1
                </a>
              </h4>
            </div>
            <div id="collapseOne" class="panel-collapse">
              <div class="panel-body">

                 <div class="panel-group" id="accordion">
          <div class="panel panel-default">
            <div class="panel-heading" id="innerhead1">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion">
                  Tab1
                </a>
              </h4>
            </div>
            <div id="innercollapseOne" class="panel-collapse">
              <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
              </div>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading" id="innerhead2">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion">
                Tab2
                </a>
              </h4>
            </div>
            <div id="innercollapseTwo" class="panel-collapse collapse">
              <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
              </div>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading" id="innerhead3">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion">
                 Tab3
                </a>
              </h4>
            </div>
            <div id="innercollapseThree" class="panel-collapse collapse">
              <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
              </div>
            </div>
          </div>
        </div>
        </div>

              </div>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading" id="head2">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion">
                Tab2
                </a>
              </h4>
            </div>
            <div id="collapseTwo" class="panel-collapse collapse">
              <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
              </div>
            </div>
          </div>
          <div class="panel panel-default">
            <div class="panel-heading" id="head3">
              <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion">
                 Tab3
                </a>
              </h4>
            </div>
            <div id="collapseThree" class="panel-collapse collapse">
              <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
              </div>
            </div>
          </div>

JavaScript的:

 $("#head1").click(function()
         {
            $("#collapseOne").toggle();
         });

        $("#innerhead1").click(function()
         {
            $("#innercollapseOne").toggle();
         });

        $("#innerhead2").click(function()
         {
            $("#innercollapseTwo").toggle();
         });


       $("#innerhead3").click(function()
         {
            $("#innercollapseThree").toggle();
         });     


         $("#head2").click(function()
         {
            $("#collapseTwo").toggle();
         });

         $("#head3").click(function()
         {
            $("#collapseThree").toggle();
         });