twitter-bootstrap 一个下拉菜单,里面有下拉菜单(Bootstrap-navbar)用于平板电脑
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17883852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A dropdown menu who have dropdown's inside (Bootstrap-navbar) for tablet
提问by toshiro92
I tried to make a navbar with a dropdown menu inside, but in this, i wan't a dropdown menu inside. But when i click on it, the menu close. I wan't to block this function who when i click on it disapears, because i think it's because of that it cannot works. I saw a thing about stopPropagation on https://github.com/twitter/bootstrap/pull/3383but i don't know where i can declare this, and it isn't a formular.
我试图制作一个带有下拉菜单的导航栏,但在这里,我不想在里面有一个下拉菜单。但是当我点击它时,菜单关闭。我不想阻止这个功能,当我点击它时它会消失,因为我认为这是因为它无法工作。我在https://github.com/twitter/bootstrap/pull/3383上看到了一个关于 stopPropagation 的事情,但我不知道我可以在哪里声明它,它不是一个公式。
EDIT : I can't use li class="dropdown-submenu" because when you are on a mobile or a tablet, the menu close when you touch a link in it.
编辑:我不能使用 li class="dropdown-submenu" 因为当您使用手机或平板电脑时,当您触摸其中的链接时菜单会关闭。
There is my code :
有我的代码:
<div class="bs-docs-example">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/app/alink">Title</a>
<div class="nav-collapse collapse navbar-responsive-collapse">
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Article A<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/app/alink">Title Article 1-A</a></li>
<li><a href="/app/alink">Title Article 2-A</a></li>
</ul>
</li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">More ...<b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Article B<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/app/alink">article 1-B</a></li>
</ul>
</li>
<li><a href="#" class="dropdown-toggle" data-toggle="dropdown">Article C<b class="caret"></b></a></li>
<li><a href="#" class="dropdown-toggle" data-toggle="dropdown">Article D<b class="caret"></b></a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
回答by toshiro92
I found another solution. I added that after my code :
我找到了另一个解决方案。我在我的代码之后补充说:
<script type="text/javascript">
$('.dropdown-menu').click(function(event){
event.stopPropagation();
});
</script>
Dropdown can't works with this solution, so i used "dropdown-submenu" to fix that (Thanks @Schmalzy for that). So when i touch a link, the submenu open. the submenu can't works normally on a tablet without the code above.
Dropdown 无法使用此解决方案,因此我使用“下拉子菜单”来解决该问题(感谢 @Schmalzy)。因此,当我触摸链接时,子菜单会打开。如果没有上面的代码,子菜单将无法在平板电脑上正常工作。
回答by Prem Kumar Maurya
You can use responsive dropdown menu of bootstrap3.
您可以使用 bootstrap3 的响应式下拉菜单。
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="./" class="navbar-brand">Bootstrap</a>
</div>
<nav class="navbar-collapse bs-navbar-collapse collapse" role="navigation" style="height: 1px;">
<ul class="nav navbar-nav">
<li>
<a href="./getting-started">Getting started</a>
</li>
<li>
<a href="./css">CSS</a>
</li>
<li>
<a href="./components">Components</a>
</li>
<li>
<a href="./javascript">JavaScript</a>
</li>
<li>
<a href="./customize">Customize</a>
</li>
</ul>
</nav>
</div>
</header>
回答by Mohammad Karimi
The problem is in Bootstrap V2.3.2 as you can see in this link http://getbootstrap.com/2.3.2/examples/carousel.html
问题出在 Bootstrap V2.3.2 中,您可以在此链接http://getbootstrap.com/2.3.2/examples/carousel.html 中看到
You can upgrade your bootstrap into Version 3 or use this style to fix the problem
您可以将引导程序升级到版本 3 或使用此样式来解决问题
/*Fix navbar dropdown collapsed on mobile devices*/
.dropdown-backdrop {
position: static;
}
Thanks to http://yogarelax.harpoonmysite.com/

