1

我正在使用 MVC3 Asp.Net 并尝试将 Twitter Bootstrap 实施到项目中。我得到了基本的东西,但不是下拉菜单。我有以下html代码

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../../Scripts/bootstrap.js" type="text/javascript"></script>
<link href="../../Content/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../../Content/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
</head>
 <body>
<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
       <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </a>
      <a class="brand" href="#">Test Project</a>
      <div class="nav-collapse">
        <ul class="nav">
          <li class="active"><a href="#">Main Menu</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Main Menu with SubMenu<b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li>First Menu</li>
                <li>Second Menu</li>
                <li>Third Menu</li>
            </ul>
          </li>
        </ul>
      </div><!--/.nav-collapse -->
    </div>
  </div>
</div>
<script type="text/javascript">
    jQuery(function ($) {
        alert("Starting Dropdown");
        $('.dropdown-toggle').dropdown();
    });
</script>
<asp:ContentPlaceHolder runat="server" ID="MainContent" ></asp:ContentPlaceHolder>
 </body>
 </html>

出于某种原因,下拉菜单没有出现,我尝试了几件事,但它不起作用。我不确定它是否与我使用的版本有关。他们是

ASP.NET MVC3

jQuery 1.5.1 Bootstrap CSS - v2.1.1 Bootstrap 下载 JS - v2.1.1

我将不胜感激这方面的任何帮助

4

2 回答 2

2

Twitter Bootstrap 使用 jQueryon()函数来委派事件,该函数是在 1.7 版中引入的。您需要至少升级到该版本才能使 jQuery 插件(例如bootstrap-collapse.js)运行。

于 2012-09-10T16:18:01.163 回答
0

You are ommiting the dropdown for collapsed state:

<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
</a>

And you are forcing that collapsed state with class collapse, delete it:

<div class="nav-collapse">
于 2012-09-10T15:59:48.950 回答