duanchigeng4313 2018-11-23 02:23
浏览 1021
已采纳

在同一页面弹出窗口中显示另一页面的模态内容

Similar questions like this has been posted before but none solved my issue. I'm trying to get enrollments.php page to show as a modal popup within index.php page

index.php

<button class="sess_btn sess_btn1" id="btn_enrol">Enrollments</button>  
<div id="enrolModal"></div>

<script>
$(document).ready(function() {
    //button modal
    $('#btn_enrol').click(function(){
        //using ajax post
        $.post('enrollments.php',function() {
            $('#enrolModal').html(); //Fill DIV enrolModal with enrollments.php content
        })
    //Calling Modal
    $('#myModal').modal('show');
    })
})
//-------------
</script>

enrollments.php

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">&times;</span>
      <h2>Modal Header</h2>
    </div>
    <div class="modal-body">
      <p>Some text in the Modal Body</p>
      <p>Some other text...</p>
    </div>
    <div class="modal-footer">
      <h3>Modal Footer</h3>
    </div>
  </div>

</div>

Also, when I try to click on the button several times there are quick blinks on the browser window. Any help will be appreciated, thanks.

  • 写回答

2条回答

  • duai1683 2018-11-25 22:59
    关注

    Thanks for the answer, I got it done a little differently. Instead of a button I used a link as shown.

    index.html

    <script>
        $(document).ready(function() {              
            $('.li-modal').on('click', function(e){
                e.preventDefault();
                $('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
            })
        });
    </script>
    
        <a href="enrollments.php" class="li-modal" id="enrol_link" onMouseOver="this.style.background='rgb(0,66,79)'" onMouseOut="this.style.background='#4CAF50'">Enrollments</a>
    
        <div class="modal fade text-center" id="theModal">
            <div class="modal-dialog">
                <div class="modal-content">
                </div>
            </div>
        </div>   
    

    enrollments.php

    <script>
    // Get the modal
    var modal = document.getElementById('theModal');
    
    // Get the <span> element that closes the modal
    var span = document.getElementsByClassName("close")[0];
    
    // When the user clicks on <span> (x), close the modal
    span.onclick = function() {
        modal.style.display = "none";
        window.location.href = "updatesession.php";
    }
    
    // When the user clicks anywhere outside of the modal, close it
    window.onclick = function(event) {
        if (event.target == modal) {
            modal.style.display = "none";
            window.location.href = "updatesession.php";
        }
    }
    </script>
    
        <div id="model-content">
            <div class="modal-header">
              <span id="close" class="close">&times;</span>
              <p>Session Editor</p>
            </div>
            <div class="modal-body">
              <p>Select Session: </p>
            </div>
            <div class="modal-footer">
              <p>Modal Footer</p>
            </div>
        </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题