jQuery Bootstrap 3 折叠菜单在移动屏幕上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30858301/
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
Bootstrap 3 collapsed menu not working on mobile screens
提问by imjp
It seems a lot of people are having this trouble (https://github.com/twbs/bootstrap/issues/7968), but the solution that worked for some is not working for me.
似乎很多人都遇到了这个问题(https://github.com/twbs/bootstrap/issues/7968),但对某些人有用的解决方案对我不起作用。
If you try to open my website at http://axxon.coand resize the window until the burger menu appears, you'll notice that nothing happens if you click on the items with a submenu (benefits or industries).
如果您尝试在http://axxon.co上打开我的网站并调整窗口大小直到出现汉堡菜单,您会注意到如果您单击带有子菜单(福利或行业)的项目,则没有任何反应。
Does anyone have any idea what I could do to fix this?
有谁知道我能做些什么来解决这个问题?
回答by AngularJR
Have a look at the Fiddle here, or the snippet below.
It only has standard Bootstrap css/js. And your menu, which works fine, no problem like in your website. Have a look to see if you have some js closing the link when clicked.
它只有标准的 Bootstrap css/js。您的菜单运行良好,没有您网站上的问题。看看你是否有一些 js 在点击时关闭链接。
I think you will find the issue is in this file axxon/js/creative.js
. The problem that closes the menu when clicked.
我想你会发现问题出在这个文件中axxon/js/creative.js
。单击时关闭菜单的问题。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Starter Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll logo logo_black" href="http://axxon.co/">
Axxon Tracking
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a href="./">Home</a>
</li>
<li>
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" href="./benefits.php">Benefits <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="./reduce-fuel-costs.php">Reduce Fuel costs</a></li>
<li><a href="./eliminate-theft-and-waste.php">Eliminate Theft and Waste</a></li>
<li><a href="./reduce-maintenance-costs.php">Reduce Maintenance Costs</a></li>
<li><a href="./reduce-labor-costs.php">Reduce Labor Costs</a></li>
<li><a href="./improve-safety.php">Improve Safety</a></li>
</ul>
</li>
<li>
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" href="./industries.php">Industries <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="./construction-and-heavy-equipment.php">Construction & Heavy Equipment</a></li>
<li><a href="./distribution.php">Distribution</a></li>
<li><a href="./transportation.php">Transportation</a></li>
<li><a href="./insurance.php">Insurance</a></li>
</ul>
</li>
<li>
<a href="./contact.php">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>
回答by Dom UIXNZ
Looks like your li's are missing the class 'dropdown'
看起来您的 li 缺少“下拉列表”类
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
<span>Test</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">...
回答by hamx0r
I had this problem with Bootstrap 3.3.6, but it was user error. One has to load jQuery beforeloading bootstrap, like so:
我在 Bootstrap 3.3.6 上遇到了这个问题,但这是用户错误。必须在加载引导程序之前加载jQuery ,如下所示:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>