admin管理员组文章数量:1416642
I'm trying to create an "expandable" menu. So, if a user clicks on option A two suboptions should show up. I'm trying to do something like this but in a menu...
This is my code so far...
<li>
<a href="?op=1" data-toggle="collapse" data-target=".nav-collapse88"><i class="icon-picture icon-white"></i> Galleries</a>
<div class="nav-collapse88">
<ul>
<li>
<a href=""><i class="icon-play"></i> Add</a>
</li>
<li>
<a href=""><i class="icon-play"></i> Delete</a>
</li>
</ul>
</div>
</li>
So when I click on galleries the options Add and Delete should appear. Any suggestions?
I'm trying to create an "expandable" menu. So, if a user clicks on option A two suboptions should show up. I'm trying to do something like this but in a menu...
This is my code so far...
<li>
<a href="?op=1" data-toggle="collapse" data-target=".nav-collapse88"><i class="icon-picture icon-white"></i> Galleries</a>
<div class="nav-collapse88">
<ul>
<li>
<a href=""><i class="icon-play"></i> Add</a>
</li>
<li>
<a href=""><i class="icon-play"></i> Delete</a>
</li>
</ul>
</div>
</li>
So when I click on galleries the options Add and Delete should appear. Any suggestions?
Share Improve this question edited Dec 14, 2012 at 14:53 Michael Berkowski 271k47 gold badges450 silver badges394 bronze badges asked Dec 14, 2012 at 14:24 CornwellCornwell 3,4108 gold badges54 silver badges85 bronze badges 1- Bootstrap Dropdown Reference – Mark Meyer Commented Dec 14, 2012 at 14:26
4 Answers
Reset to default 4I would nest ul's like so:
<ul>
<li>
<a class="expand">Link used to expand</a>
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
</ul>
The I would use this jquery:
$(document).on('click', 'a.expand', function(e) {
e.preventDefault();
$(this).siblings('ul').slideToggle();
});
You would need to set the sub menu CSS to display none.
Something along these lines should do the trick.
This works:
<ul>
<li class="dropdown">
<a href="?op=1">Support</a>
<ul class="dropdown-menu" role="menu">
<li><a href=""><i class="icon-play"></i> Add</a></li>
<li><a href=""><i class="icon-play"></i> Delete</a></li>
</ul>
</li>
</ul>
I believe you want the class to be dropdown not collapse. That's how the bootstrap documentation remends it for menus.
Change the class to be dropdown
, remove the inner div, and add the class dropdown-menu
the inner ul.
<li class="dropdown">
<a href="?op=1" data-toggle="dropdown"><i class="icon-picture icon-white"></i>>Galleries</a>
<ul class="dropdown-menu">
<li>
<a href=""><i class="icon-play"></i> Add</a>
</li>
<li>
<a href=""><i class="icon-play"></i> Delete</a>
</li>
</ul>
</li>
tyy this http://jsfiddle/68RXP/213/
$(function(){
$(".nav-collapse88").hide();
$("a").click(function(e){
e.preventDefault();
$(".nav-collapse88", $(this).parent()).slideToggle();
});
})
<li>
<a href="?op=1">
<i class="icon-picture icon-white"></i> Galleries</a>
<div class="nav-collapse88">
<ul>
<li>
<a href=""><i class="icon-play"></i> Add</a>
</li>
<li>
<a href=""><i class="icon-play"></i> Delete</a>
</li>
</ul>
</div>
</li>
本文标签: javascriptExpand menushow submenuStack Overflow
版权声明:本文标题:javascript - Expand menu, show submenu - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745252736a2649920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论