模态表单不显示 [英] Modal Form not showing up

查看:51
本文介绍了模态表单不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .jsp 文件,其中有一个标题,其中包含一个 ID 为modalFormButton"的按钮,按下该按钮时必须显示一个模态表单.模态表单的代码位于另一个 .jsp 文件中,因此我正在动态添加它.我已经检查过它是否成功调用了包含所述内容的文件,但它没有显示表单.我还尝试将表单代码放在我调用它的同一个 .jsp 中,但它也不起作用.

PS:模态表单包含在 id 为agregarClienteModal"的 div 中.另外,我正在使用 Bootstrap.

.jsp 主文件:

<头><元字符集=utf-8"><元名称=视口"内容=宽度=设备宽度,初始比例=1"><!-- Bootstrap CSS --><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css";rel=样式表"完整性=sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6";crossorigin =匿名"><title>JSP页面</title><身体><header class = "py-2 bg-info text-white><div><h1>客户<按钮类型=按钮";id = "modalFormButton";class="btn btn-primary btn-block data-toggle="modal"数据目标=#agregarClienteModal">客户群

<jsp:include page="addClientModalForm.jsp"/></标题><script src=https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"完整性=sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"crossorigin=匿名"></script>

模态代码:

<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";数据关闭=模态"><span>&times;</span>

<form action="${pageContext.request.contextPath}/servlet?accion=insertar";方法=POST"class=已验证"><div class="modal-body"><div class="form-group"><label for="nombre">Nombre</label><输入类型=文本"类=表单控制"名称=名词"需要>

<div class="form-group"><label for=apellido">Apellido</label><输入类型=文本"类=表单控制"名称=apellido"需要>

<div class="form-group"><label for="email">Email</label><输入类型=电子邮件"类=表单控制"名称=电子邮件"需要>

<div class="form-group"><label for="telefono">Teléfono</label><输入类型=电话"类=表单控制"名称=电话"需要>

<div class="form-group"><label for=saldo">Saldo</label><输入类型=数字"类=表单控制"名称=萨尔多"所需的步骤=任何">

<div class="modal-footer"><button class="btn btn-primary";type="submit">Guardar;

</表单>

解决方案

data- 属性在 Bootstrap 5 中对 data-bs- 进行了更改...

<h1>客户端 </h1><按钮类型=按钮"id="modalFormButton";class =btn btn-primary btn-block"data-bs-toggle=模态"data-bs-target=#agregarClienteModal">Agregar 客户 </button>

演示

I have a .jsp file on which I have a header that contains a button with id "modalFormButton", which when pressed must display a modal form. The code for the modal form is in another .jsp file so I am adding it dynamically. I already checked that if it is successfully calling the file with said content but it does not display the form. I also tried putting the form code in the same .jsp I called it from and it didn't work either.

PS: The modal form is contained within a div with an id of "agregarClienteModal". Also, I am using Bootstrap.

.jsp main file:

<!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>

Modal form code:

<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>&times;</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>

解决方案

The data- attributes have changes to data-bs- in Bootstrap 5...

<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

这篇关于模态表单不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
Java开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆