dqyl2374 2016-04-14 07:10
浏览 82
已采纳

php echo和JQuery .load中的bootstrap modal

I have index.php which calls other test.php using jQuery and loads the contents in one div tag.

But if I put modal in echo of test.php it doesn't work. Modal does not open.

Here is my index.php

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="css/bootstrap.css">
    <link type="text/css" rel="stylesheet" href="css/custom.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
  </head>
  <body>
    <div id="try"></div>
  </body>
  <script>
    function loadUnSolved(){
      $("#try").load("test.php");
    }
    $(document).ready(loadUnSolved());
  </script>
</html>

test.php

<?php
echo '
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="modal12">Otryl</button>

<!-- Modal -->
<div id="modal12" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>text</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>';
?>

I think the problem is in $(document).ready()

  • 写回答

2条回答 默认 最新

  • douhui9380 2016-04-14 07:26
    关注

    Try the following

    Index.php :

    <script>
        function loadUnSolved(){
            $("#try").load("test.php");
        }
    
        $(document).ready(function(){loadUnSolved()});
    </script>
    

    test.php :(you missed the # symbol)

    <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#modal12">Otryl</button>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)