[英]closing dropdown menu after clicking on a menu item
when i click on a button a menu dropdown appears with menu items within. 当我单击一个按钮时,会出现一个菜单下拉菜单,其中包含菜单项。 Currently when i click on a menu item the page changes to the clicked content but the menu list still appear and doesn't go away after clicking on a menu item. 当前,当我单击菜单项时,页面将更改为单击的内容,但是菜单列表仍然出现,并且在单击菜单项后不会消失。 What do i need to add to my script so that after clicking on any of the menu items the menu would close. 我需要添加什么到脚本中,以便在单击任何菜单项后菜单将关闭。
menu button: 菜单按钮:
<button type="button" class="btn btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
</button>
<div class="nav-collapse collapse" style="height: 0px;">
<ul id="Menu" data-bind="template: { name: 'menuItems', foreach: menuItemList, as: 'menuItem' }" class="nav">
</ul>
</div>
this is the script when clicking on a menu item: 这是单击菜单项时的脚本:
<script type="text/html" id="menuItems">
<li class="dropdown" data-bind="css: { active: isActive }">
<a class="dropdown-toggle" data-bind="text: title, attr: { href: url }">
</a>
</li>
</script>
Instead of doing what you're doing, I would recommend utilizing javascript to achieve a DDL list with UL's and LI elements. 我建议您使用JavaScript来实现带有UL和LI元素的DDL列表,而不是执行您的操作。
var _ddls = $(".DropDownList"); _ddls.click(function() { $(this).children().slideUp(); }); _ddls.hover(function() { $(this).children().slideDown(); }, function() { $(this).children().slideUp(); });
.DropDownList { list-style:none; } .DropDownList li { display:none; } #ddl_example { background-color:red; width:100px; height:20px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <ul id="ddl_example" class='DropDownList'>Menu <li id='option1'><a href='javascript:void()'>Option 1</a></li> <li id='option2'><a href='javascript:void()'>Option 2</a></li> <li id='option3'><a href='javascript:void()'>Option 3</a></li> <li id='option4'><a href='javascript:void()'>Option 4</a></li> <li id='option5'><a href='javascript:void()'>Option 5</a></li> <li id='option6'><a href='javascript:void()'>Option 6</a></li> </ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.