你生成的代码中有很多错误,所以我在这里做了一些,所以你可以看到发生了什么。我已经删除了手风琴菜单不需要的所有内容。
<div class="accordion">
<ul id="accordion1" class="collapse in">
<li>
<a href="#accordion2" data-toggle="collapse" >About</a>
<ul id="accordion2" class="collapse">
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/about/bio">Biography</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/about/cv">CV</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/about/press">Press</a>
</li>
</ul>
</li>
<li>
<a href="#accordion3" data-toggle="collapse" >Work</a>
<ul id="accordion3" class="collapse">
<li>
<a href="#accordion4" data-toggle="collapse">Cornwall</a>
<ul id="accordion4" class="collapse">
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/cornwall/cornwall_early">Cornwall 58-65</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/cornwall/cornwall">Cornwall 66-69</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/cornwall/cornwall_wave">Cornwall 69, Wave</a>
</li>
</ul>
</li>
<li>
<a href="#accordion5" data-toggle="collapse">Whale Moor & Lake District</a>
<ul id="accordion5" class="collapse">
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/whale_moor/one">Lakeland Hills 72-74</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/whale_moor/two">Lakeland Hills 74-76</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/whale_moor/three">Lakeland Hills 80</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/whale_moor/four">High Places 82-83</a>
</li>
<li class="active">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/whale_moor/lakes">Lakes of Cumberland 82</a>
</li>
</ul>
</li>
<li>
<a href="#accordion6" data-toggle="collapse">Galloway & Scottish Coast</a>
<ul id="accordion6" class="collapse">
<li class="depth-3">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/galloway/first">Galloway Coast 72-74</a>
</li>
<li class="depth-3">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/galloway/drumbreddan">Drumbreddan 76</a>
</li>
<li class="depth-3">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/galloway/pebble">Pebble Series 77-79</a>
</li>
<li class="depth-3">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/galloway/fidden">Fidden & The Isle of Mull</a>
</li>
<li class="depth-3">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/galloway/later">Later</a>
</li>
</ul>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/durdle">South Coast</a>
</li>
<li>
<a href="#accordion7" data-toggle="collapse">Figures</a>
<ul id="accordion7" class="collapse">
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/figures/one">Figures 81</a>
</li>
<li">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/figures/two">Figures 82-84</a>
</li>
<li class="depth-3">
<a data-toggle="collapse" href="http://www.medlargroup.com/work/figures/three">Figures on the Beach 83</a>
</li>
</ul>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/london">London</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/mersey">Merseyside</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/northumberland">Northumberland</a>
</li>
<li>
<a href="#accordion8" data-toggle="collapse" >Wales & the Llyn Peninsula</a>
<ul id="accordion8" class="collapse">
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/wales/one">Llanina 82</a>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/work/wales/two">llyn</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a data-toggle="collapse" href="http://www.medlargroup.com/contact">Contact</a>
</li>
</ul>
</div>
这将整理代码,以便各种 css 选择器和 javascript 可以正常工作。此外,要保持活动菜单项打开,您需要向活动“li”元素添加一个类“活动”,然后运行此代码;
<script type="text/javascript">
$('.active').parentsUntil('div.accordion').addClass('in');
</script>
这将为活动元素的每个父级添加一个“in”类,直到顶层。这将使它们为您打开。