我正在尝试使Modals与我的页面一起使用,我将Spring-mvc 3.2与bootstrap 3.0.3一起使用。
单击“添加用户”按钮没有任何效果,甚至在我将模式视图设置为显示时也没有效果,无法使用关闭按钮将其关闭。

我该如何解决?

这是jsp页面代码:

<!doctype html>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
  <head>
    <meta charset="utf-8">
    <titlTest modals</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="<c:url value="/resources/css/bootstrap.css" />" rel="stylesheet"  type="text/css" />

    <script type="text/javascript" src='<c:url value="/resources/js/bootstrap.js" />'></script>
    <script type="text/javascript" src='<c:url value="/resources/js/jquery-1.9.1.js" />'></script>
</head>

<body>
    <div class="container">
        <button class="btn btn-danger btn-mini" data-toggle="modal" data-target="#editUserModal">
            Add user
        </button>
    </div>
    <div class="modal fade" id="editUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <form:form method="post" action="/admin/users/update" commandName="user" role="form">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Modify user</h4>
                    </div>
                    <div class="modal-body">
                        <form:hidden path="id" placeholder="Id" value="${user.id}"/>
                        <div class="form-group">
                            <form:label path="firstName">First Name:</form:label>
                            <form:input path="firstName" class="form-control" placeholder="First Name" value="${user.firstName}"/>
                        </div>
                        <div class="form-group">
                            <form:label path="lastName">Last Name:</form:label>
                            <form:input path="lastName" class="form-control" placeholder="Last Name" value="${user.lastName}"/>
                        </div>
                        <div class="form-group">
                            <form:label path="email">Email:</form:label>
                            <form:input path="email" class="form-control" placeholder="Email" value="${user.email}"/>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">Save changes</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div><!-- /.modal-content -->
            </form:form>
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</body>




产生的HTML代码:

<html>
<head>
    <meta charset="utf-8">
    <title>Test modals</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="/resources/css/bootstrap.css" rel="stylesheet"  type="text/css" />

    <script type="text/javascript" src='/resources/js/bootstrap.js'></script>
    <script type="text/javascript" src='/resources/js/jquery-1.9.1.js'></script>
</head>

<body>
    <div class="container">
            <button class="btn btn-danger btn-mini" data-toggle="modal" data-target="#editUserModal">
                Add user
            </button>
    </div>
    <div class="modal fade" id="editUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <form id="user" role="form" action="/admin/users/update" method="post">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Modify user</h4>
                    </div>
                    <div class="modal-body">
                        <input id="id" name="id" placeholder="Id" value="0" type="hidden" value="0"/>
                        <div class="form-group">
                            <label for="firstName">First Name:</label>
                            <input id="firstName" name="firstName" placeholder="First Name" class="form-control" type="text" value=""/>
                        </div>
                        <div class="form-group">
                            <label for="lastName">Last Name:</label>
                            <input id="lastName" name="lastName" placeholder="Last Name" class="form-control" type="text" value=""/>
                        </div>
                        <div class="form-group">
                            <label for="email">Email:</label>
                            <input id="email" name="email" placeholder="Email" class="form-control" type="text" value=""/>
                        </div>
                        <div class="form-group">
                            <label for="password">Password:</label>
                            <input id="password" name="password" placeholder="Password" class="form-control" type="text" value=""/>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">Save changes</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div><!-- /.modal-content -->
            </form>
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</body>

最佳答案

您需要先包含jquery,然后包含bootstrap,因为bootstrap需要jquery才能起作用。

因此,切换了这两行代码

 <script type="text/javascript" src='<c:url value="/resources/js/jquery-1.9.1.js" />'></script>
 <script type="text/javascript" src='<c:url value="/resources/js/bootstrap.js" />'></script>

10-07 19:44
查看更多