模态表单未显示[重复]
Posted
技术标签:
【中文标题】模态表单未显示[重复]【英文标题】:Modal Form not showing up [duplicate] 【发布时间】:2021-06-26 16:06:28 【问题描述】:我有一个 .jsp 文件,其中有一个标题,其中包含一个 ID 为“modalFormButton”的按钮,按下该按钮时必须显示一个模态表单。模态表单的代码在另一个 .jsp 文件中,所以我动态添加它。我已经检查过它是否成功调用了具有上述内容的文件,但它没有显示表单。我还尝试将表单代码放在我调用它的同一个 .jsp 中,但它也不起作用。
PS:模态表单包含在 id 为“agregarClienteModal”的 div 中。另外,我正在使用 Bootstrap。
.jsp 主文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<title>JSP Page</title>
</head>
<body>
<header class = "py-2 bg-info text-white">
<div>
<h1>
Clients
</h1>
<button type = "button" id = "modalFormButton" class="btn btn-primary btn-block data-toggle="modal" data-target="#agregarClienteModal">
Agregar Cliente
</button>
</div>
<jsp:include page="addClientModalForm.jsp"/>
</header>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
</body>
</html>
模态代码:
<div class="modal fade" id="agregarClienteModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-info text-white">
<h5 class="modal-title">Agregar Cliente</h5>
<button class="close" data-dismiss="modal">
<span>×</span>
</button>
</div>
<form action="$pageContext.request.contextPath/servlet?accion=insertar"
method="POST" class="was-validated">
<div class="modal-body">
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" class="form-control" name="nombre" required>
</div>
<div class="form-group">
<label for="apellido">Apellido</label>
<input type="text" class="form-control" name="apellido" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" required>
</div>
<div class="form-group">
<label for="telefono">Teléfono</label>
<input type="tel" class="form-control" name="telefono" required>
</div>
<div class="form-group">
<label for="saldo">Saldo</label>
<input type="number" class="form-control" name="saldo" required step="any">
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="submit">Guardar</button>
</div>
</form>
</div>
</div>
</div>
【问题讨论】:
【参考方案1】:data-
属性在 Bootstrap 5 中更改为 data-bs-
...
<div>
<h1> Clients </h1>
<button type="button" id="modalFormButton" class="btn btn-primary btn-block" data-bs-toggle="modal" data-bs-target="#agregarClienteModal"> Agregar Cliente </button>
</div>
Demo
【讨论】:
以上是关于模态表单未显示[重复]的主要内容,如果未能解决你的问题,请参考以下文章