如何激活和打开父菜单和子菜单在导航侧栏中

时间:2018-09-07 05:09:12

标签: jquery html navbar

    <li class="nav-item start ">
                <a href="javascript:;" class="nav-link nav-toggle">
                    <i>
                        <img src="~/images/MenuIcons/UserManagement.png" width="25" height="25" />
                    </i>
                    <span class="title">User Management</span>
                    <span class="arrow"></span>
                </a>
                <ul class="sub-menu">
                    <li class="nav-item start ">
                        <a asp-controller="Roles" asp-action="Index" class="nav-link ">
                            <i>
                                <img src="~/images/MenuIcons/Roles.png" height="25" width="25" />
                            </i>
                            <span class="title">Roles</span>
                        </a>
                    </li>
                    <li class="nav-item start ">
                        <a asp-controller="UserAccount" asp-action="Register" class="nav-link ">
                            <i class="fa"><img src="~/images/MenuIcons/Register-512.png" height="25" width="25" /></i>
                            <span class="title">Register</span>
                        </a>
                    </li>
                </ul>
            </li>



        <script>
           $(document).ready(function () {
               debugger;
               var url = window.location.pathname;
               var currentElement = $('li .nav-item .sub-menu a[href="' + url + '"]');
               currentElement.parent().addClass('active open');

           })
       </script>

li放在我的部分菜单中。对于导航侧栏,我正在调用部分视图,并将脚本标签放置在布局页面中以使其处于活动状态,并打开父级和子级菜单,但不起作用。请帮助我。我该如何解决。

0 个答案:

没有答案