我正在尝试实现一个导航菜单,其中包含一个 UL > LI 块:
<aside id="nav-container" role="complementary" style="width: 232px;">
<nav class="overview" id="primary-nav" role="nav" style="display: block;">
<h3 class="section">
<span class="menu-toggle"></span>
<span>The Basics</span>
</h3>
<ul class="depth-1 shortcuts" style="display: none;">
<li><a href="#" class="nav-link">Introduction</a></li>
<li><a href="#" class="nav-link">A Chapter in the Zeitgeist Movement</a></li>
<li><a href="#" class="nav-link">Getting Real with expectations</a></li>
<li><a href="#" class="nav-link">Point of Focus in a chapter</a></li>
</ul>
<h3 class="section">
<span class="menu-toggle"></span>
<span>Setting up a National Chapter</span>
</h3>
<ul class="depth-1 shortcuts" style="display: none;">
<li><a href="#" class="nav-link">Gathering Volunteers & Social Media</a></li>
<li><a href="#" class="nav-link">Establishing a Website & Tools</a></li>
<li><a href="#" class="nav-link">Organising a Core Group</a></li>
<li><a href="#" class="nav-link">Expanding into Regional Chapters</a></li>
</ul>
<h3 class="section">
<span class="menu-toggle"></span>
<span>Setting up a city or local Chapter</span>
</h3>
<ul class="depth-1 shortcuts" style="display: none;">
<li><a href="#" class="nav-link">Introduction</a></li>
<li><a href="#" class="nav-link">Getting Started</a></li>
<li><a href="#" class="nav-link">Raising Volunteers</a></li>
<li><a href="#" class="nav-link">Organising a Core Group</a></li>
</ul>
<h3 class="section">
<span class="menu-toggle"></span>
<span>Organising Events</span>
</h3>
<ul class="depth-1 shortcuts" style="display: none;">
<li><a href="#" class="nav-link">Types of Events</a></li>
<li><a href="#" class="nav-link">Finding a Space</a></li>
<li><a href="#" class="nav-link">Gathering Materials</a></li>
<li><a href="#" class="nav-link">Promoting the Event</a></li>
<li><a href="#" class="nav-link">Executing the Event</a></li>
</ul>
<h3 class="section">
<span class="menu-toggle"></span>
<span>Organising Project Teams</span>
</h3>
<ul class="depth-1 shortcuts" style="display: none;">
<li><a href="#" class="nav-link">“Your idea, your project” concept</a></li>
<li><a href="#" class="nav-link">Guidelines</a></li>
<li><a href="#" class="nav-link">Project Methodology</a></li>
<li><a href="#" class="nav-link">Devising a Project Structure</a></li>
<li><a href="#" class="nav-link">Organising Volunteers </a></li>
</ul>
<h3 class="section">
<span class="menu-toggle"></span>
<span>Appendix</span>
</h3>
<ul class="depth-1 shortcuts" style="display: none;">
<li><a href="#" class="nav-link">Tips from Coordinators</a></li>
<li><a href="#" class="nav-link">Tips on DVDs</a></li>
</ul>
</nav>
</aside>
最初所有的都是关闭的,当我点击一个h3时,ul列表变成了
我有这个 javascript 代码:
// menu open close
this.leftMenuToggle = function () {
var leftMenuToggle = $( ".section" ).on( "click", function( event ) {
event.preventDefault();
leftMenuToggle.toggleClass("active");
leftMenuToggle.next().css('display', 'block');
console.log('we clicked this menu item');
});
}
但它会打开所有 .section 项目,更改我的代码的正确方法是什么,以便如果我点击...它只打开子 ul 列表?
谢谢