Bootstrap下拉列表不起作用

时间:2016-11-07 12:53:17

标签: twitter-bootstrap jsp

您好我试图在glassfish服务器和Intellij IDE上使用Java EE建立一个网站。我尝试使用带有下拉菜单的引导程序导航栏,但下拉列表不起作用。 我的架构是changelog

还有我的代码: 1)layout.tag

<%@tag description="Overall Page template" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@attribute name="title" fragment="true"%>
<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="<c:url value="/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css"/>"/>
    <link rel="stylesheet" href="<c:url value="/lib/font-awesome-4.7.0/css/font-awesome.min.css"/>"/>
    <link rel="stylesheet" href="<c:url value="/css/custom.css"/>"/>
    <title>MyChild - <jsp:invoke fragment="title"/></title>
</head>

<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- 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" 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>
            <a class="navbar-brand" href="#">Brand</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">
                <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                <li><a href="#">Link</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul>
                </li>
            </ul>
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search">
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">Link</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>


<div id="body">
    <jsp:doBody/>
</div>


<div id="pagefooter">
    <p>FOOTER</p>
</div>


<script type="text/javascript" href="<c:url value="/lib/jquery/jquery-3.1.1.min.js"/>"></script>
<script type="text/javascript" href="<c:url value="/lib/jquery-ui-1.12.1.custom/jquery-ui.min.js"/>"></script>
<script type="text/javascript" href="<c:url value="/lib/bootstrap-3.3.7-dist/js/bootstrap.min.js"/>"></script>
</body>
</html>

2)index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
<t:layout>
  <jsp:attribute name="title">home</jsp:attribute>
  <jsp:body>
    <p>WELCOME</p>
  </jsp:body>
</t:layout>

bootstrap CSS工作,但下拉菜单不起作用。如果我点击“源代码”&#39;在firefox中,我可以看到所有需要的文件(bootstrap.min.js等),以便系统知道文件的位置。

我看到我们必须有一个有效的doctype,当我点击&#34;源代码&#34;在firefox上我在标记之前有5个空行。也许问题出在那里?

ps:它适用于CDN。

2 个答案:

答案 0 :(得分:0)

查看this jsp并注意顺序。我正在使用您提到的所有bootstrap / jquery / popper css和js。并且其正常工作(按预期)。

答案 1 :(得分:-1)

尝试在末尾的脚本标记后添加以下代码

if( vkCode == 88)
{
    ...
    return 0;
}