$(...)。modal不是函数

时间:2016-05-16 14:38:56

标签: jquery twitter-bootstrap

当我导入脚本和css时,这是我的<head> .php。

<!--JQUERY-->
<script       src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">       </script>
<!--JQUERY-UI-->
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet"   href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<!-- BS JavaScript -->
<script type="text/javascript" src="js/bootstrap.js"></script>
<!--CSS BOOTSTRAP-->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- SIDEBAR CSS -->
<link href="../css/simple-sidebar.css" rel="stylesheet">
<!--Modal Form-->
<?php include "modal_form_detalle_parteMantenimiento.php"; ?>

这是用信息

打开模态表单的函数
$(document).ready(function(){
                           var id_clickat=0;
                           $('[name=detalles]').click(function(){
                               id_clickat = $(this).val();

                                $.post( "../php/ajaxParteMantenimiento.php",{id_c : id_clickat, mostrar : true}, function( data )                           
                        {    
                            $("#contenidoDetalleMant").html(data);
                            $('#contenidoDetalleMant').modal('show');
                        });
                           });
                       });

模态形式是简单的html:

<!DOCTYPE html>
<div id="pintarAsiTot">
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

</head>

<body>
<!-- Modal -->

<div class="modal fade" id="detalleParteMantenimiento" tabindex="-1" role="dialog" 
 aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <!-- Modal Header -->
        <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal">
                   <span aria-hidden="true">&times;</span>
                   <span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title" id="myModalLabel">
                Detalle Parte Mantenimiento
            </h4>
        </div>

        <!-- Modal Body -->
        <div class="modal-body">

            <form class="form-horizontal" role="form">
              <div class="form-group" id="contenidoDetalleMant">                            




                </div>



              </div>
              <!-- Modal Footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">CERRAR</button>
            </div>

            </form>

        </div>


    </div>
</div>
</div>

</body>

</html>


</div>

问题是当我点击按钮时没有打开表格。 ¿什么呢?

1 个答案:

答案 0 :(得分:0)

首先,模态ID是 detalleParteMantenimiento 而不是 contenidoDetalleMant ,尝试更改它。

如果这不起作用,我会检查Jquery是否正确加载或是否加载了两次,也许它已包含在您的布局页面中。

解决方法

你可以做的是添加一个隐藏按钮,如下所示:

<button type="button" id="btnToOpenModal" style="display:none" data-toggle="modal" data-target="#detalleParteMantenimiento"> </button>

然后在您的函数中单击此按钮:

$(document).ready(function(){
                       var id_clickat=0;
                       $('[name=detalles]').click(function(){
                           id_clickat = $(this).val();

                            $.post( "../php/ajaxParteMantenimiento.php",{id_c : id_clickat, mostrar : true}, function( data )                           
                    {    
                        $("#contenidoDetalleMant").html(data);
                        $("#btnToOpenModal").click();
                    });
                       });
                   });