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条)

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题