折叠窗口时,切换按钮不起作用。我不知道哪个部分是错的。
我无法判断JQuery是否未运行或是否是一个不同的问题。
<link href="~/CSS/bootstrap.min.css" rel="stylesheet">
<link href="~/CSS/starter-template.css" rel="stylesheet">
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".ttnavbar" aria-expanded="false" aria-controls="navbar">
<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" href="/Default.aspx">AS HOME</a>
</div>
<div id="navbar" class="collapse navbar-collapse ttnavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="/Default.aspx">HOME</a></li>
<li><a href="#about">aa</a></li>
<li><a href="#contact">bb</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
在页面的正文部分末尾添加这两行代码。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
我在ASP.Net中使用了一个带有切换按钮的导航栏的示例,因此您可以复制代码并检查它在哪里出错。请注意我在MasterPage文件中创建了导航栏。这是代码
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MySite.master.cs" Inherits="ProjectName.MySite" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<link href="Designs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<form id="masterPageForm" runat="server">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-target="#collapsingPart" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="collapsingPart">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Search</a></li>
</ul>
<div class="navbar-form navbar-left">
<div class="form-group">
<asp:textbox runat="server" cssclass="form-control"></asp:textbox>
<asp:button runat="server" cssclass="btn btn-primary" text="search" />
</div>
</div>
</div>
</nav>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>