折叠时,引导菜单链接不起作用

时间:2017-04-11 15:04:48

标签: javascript jquery html css twitter-bootstrap

我正在使用bootstrap定义一个菜单,我已将其修复到我的网页顶部。问题是链接正是我想要的,直到它们崩溃到下拉菜单中。一旦崩溃,它们有时只会起作用。我无法在控制台中发现任何错误,以帮助指导我们为什么大部分时间都不工作。任何想法将不胜感激!谢谢!

- 已经回复的人,谢谢!对不起,这是一个糟糕的例子。我已经删除了更多,这个例子应该运行。我还有同样的问题。我无法弄清楚为什么这些链接无法正常工作。



				function loadMenuItem (name) {
					var newHTML;
					switch(name){
						case 'home':
							newHTML = "<p>Some home page</p>";
							break;
						case 'learn':
							newHTML = "<p>Some learn page</p>";
							break;
						case 'blog':
							newHTML = "<p>Some blog page</p>";
							break;
						case 'forum':
							newHTML = "<p>Some forum page</p>";
							break;
						case 'tools':
							newHTML = "<p>Some tools page</p>";
							break;
					}
					document.getElementById("main-content").innerHTML = newHTML;
				}
				
				$(function () {
				$("#navbarToggle").blur(function (event) {
					var screenWidth = window.innerWidth;
					if(screenWidth < 768) {
						$("#collapsable-nav").collapse('hide');
					}
				});
			});
			$(".nav a").on("click", function(){
			   $(".nav").find(".active").removeClass("active");
			   $(this).parent().addClass("active");
			});
&#13;
<!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">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Test Page</title>

    <!-- Bootstrap -->
    <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
  </head>

  
	<body>
		<header>
			<nav id="header-nav" class="navbar navbar-inverse nav-justified" >
				<div class="container">
					<div class="navbar-header">
											
						
						<button id="navbarToggle" type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsable-nav" aria-expanded="false">
							<span class="sr-only">Toggle navigation</span>
							<span class="icon-bar"></span>
							<span class="icon-bar"></span>
							<span class="icon-bar"></span>
						</button>
					</div>
					
					<div id="collapsable-nav" class="collapse navbar-collapse">
						<ul id="nav-list" class="nav navbar-nav">
							<li class="active"><a href="#" onclick="loadMenuItem('home');">HOME</a></li>
							<li><a href="#" onclick="loadMenuItem('blog');">BLOG</a></li>
							<li><a href="#" onclick="loadMenuItem('forum');">FORUM</a></li>
							<li><a href="#" onclick="loadMenuItem('learn');">LEARN</a></li>
							<li><a href="#" onclick="loadMenuItem('tools');">TOOLS</a></li>
						</ul>
					</div>
				</div>
			</nav>
		</header>
		
		<!-- The main body of the page is here.  AJAX is used to dynamically change which page is visible. -->
		<div id="main-content" class="container"></div>


		
			
			<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
			<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
			<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
	</body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案