繁体   English   中英

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

[英]Show modal content from another page within same pages popup

类似的问题已经发布过,但没有一个解决我的问题。 我正在尝试让enrollments.php页面显示为index.php页面内的模式弹出窗口

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

另外,当我尝试多次单击按钮时,浏览器窗口会快速闪烁。 任何帮助将不胜感激,谢谢。

是否在代码中进行了更正,以正确使用jquery API。 未经测试,但是下面的代码可以工作。

<script>
$(document).ready(function() {
    //button modal
    $('#btn_enrol').click(function(){

        $.post( "enrollments.php", function( htmlContents ) {
          $('#enrolModal').html( htmlContents ); 

          //Show the Modal once you get enrollments.php html contents
          $('#myModal').modal('show');
        });      
    })
})
//-------------
</script>

感谢您的回答,我做的有点不同。 我使用按钮代替了按钮,如图所示。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM