gpt4 book ai didi

java - Bootstrap 3 模式窗口不适用于 spring mvc

转载 作者:行者123 更新时间:2023-12-02 06:16:03 25 4
gpt4 key购买 nike

我正在尝试使模态框与我的页面一起使用,我使用 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>

关于java - Bootstrap 3 模式窗口不适用于 spring mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21457329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com