我有一个包含一些菜单项的侧边菜单。
一个菜单项可以包含一些子菜单项
以下是我如何实现这个
<div id="mySidenav" class="sidenav mainmenu">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="@Url.Action("Index", "Home")">Home</a>
<li><a href="@Url.Action("Index", "Calendar")">Calendar</a>
<ul class="submenu">
<li><a href="@Url.Action("SheduleNewAppointment", "Calendar")">- Shedule new appointment</a></li>
</ul>
</li>
<a href="@Url.Action("Index", "PatientDatabase")">Patient Database</a>
<li><a href="@Url.Action("Index", "Findings")">Findings</a>
<ul class="submenu">
<li><a href="">- All Findings</a></li>
<li><a href="">- Open Findings</a></li>
</ul>
</li>
<li><a href="@Url.Action("Index", "Controlling")">Controlling</a>
<ul class="submenu">
<li><a href="">- Patients</a></li>
<li><a href="">- Medical Partners</a></li>
<li><a href="">- Internal Controlling</a></li>
</ul>
</li>
<li><a href="@Url.Action("Index", "Invoices")">Invoices</a>
<ul class="submenu">
<li><a href="">- Receipt of payment</a></li>
</ul>
</li>
我需要点击一个菜单项,它会显示子菜单项,如果我再次点击它会隐藏它们。我怎么能意识到这一点?
答案 0 :(得分:0)
答案 1 :(得分:0)
看到这里我申请点击甚至不打开,因为在锚点上你添加了其他页面的网址,所以22事件没有在同一个元素上被触发。检查并且如果有任何问题让我知道
$(document).ready(function() {
$('.main_wrapper li').on('click', function() {
$(this).children('.submenu').slideToggle();
});
});
&#13;
.submenu {
display: none;
}
ul li {
background-color: #000;
margin-bottom: 5px;
cursor: pointer;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="mySidenav" class="sidenav mainmenu">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="@Url.Action(" Index ", "Home ")">Home</a>
<ul class="main_wrapper">
<li><a href="@Url.Action(" Index ", "Calendar ")">Calendar</a>
<ul class="submenu">
<li><a href="@Url.Action(" SheduleNewAppointment ", "Calendar ")">- Shedule new appointment</a></li>
</ul>
</li>
<li><a href="@Url.Action(" Index ", "PatientDatabase ")">Patient Database</a></li>
<li><a href="@Url.Action(" Index ", "Findings ")">Findings</a>
<ul class="submenu">
<li><a href="">- All Findings</a></li>
<li><a href="">- Open Findings</a></li>
</ul>
</li>
<li><a href="@Url.Action(" Index ", "Controlling ")">Controlling</a>
<ul class="submenu">
<li><a href="">- Patients</a></li>
<li><a href="">- Medical Partners</a></li>
<li><a href="">- Internal Controlling</a></li>
</ul>
</li>
<li><a href="@Url.Action(" Index ", "Invoices ")">Invoices</a>
<ul class="submenu">
<li><a href="">- Receipt of payment</a></li>
</ul>
</li>
</ul>
&#13;