Модал на Модал с Jquery - PullRequest
0 голосов
/ 31 декабря 2018

Мне нужно открыть модал на другом модале, проблема в том, что первый модал теряет полосу прокрутки главной страницы после закрытия находящейся на ней модальности.

Я постараюсь объяснить лучше:

У меня есть этот модал, который загружает в модальное тело контент, который может быть обширным, исходя из запроса в Ajax

<div class="modal fade" id="modal_1">
  <div class="modal-dialog modal-lg" role="document">
     <div class="modal-content">
           <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                 <h4 class="modal-title" id="myModalLabel">Concluir </h4>
           </div>
          <div id="modal-body" class="modal-body"></div>                                
    </div>
 </div>
</div>

Я загружаю информацию, которая будет отображаться в модале.тело в следующем действии Jquery:

$(document).on('click', '#btn_open_modal1', function (event) {
event.preventDefault();        
     $.ajax ({
        type: 'POST',
        url: "load.php",
        data: {id : id},
        async: false,
        dataType: "text",     
        success: function(data){           
            $('#modal-body').html(data);
            $('#modal_1').modal('show');   
        }
      })
})

В этом модале, который открывается, есть кнопка для вызова другого модала

<button class="btn btn-success btn-block" id="confirm">Confirm</button>

В этом модале, который открывается, есть кнопка для вызова другогомодальное нажатие на эту кнопку запускает новый вызов Ajax, чтобы открыть новый модальный

<div class="modal fade" id="modal_2">
  <div class="modal-dialog modal-sm">
     <div class="modal-content">
       <div class="modal-header text-white bg-dark">Confirm: </div>
            <button class="btn btn-secondary btn-no" data-dismiss="modal">No</button>
            <a class="btn btn-primary text-white btn-yes" id="btn-yes">Yes</a>

       </div>

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

и в Jquery

$(document).on('click', '#confirm', function(event){ 
event.preventDefault();                             
    $("#modal_2").modal().find("#btn-yes").off('click').on("click", function(event){ 
           event.preventDefault();                    
                 $.ajax ({
                      type: 'POST',
                      url: "update.php",
                      data: {id : id},                 
                      dataType: "text",     
                      success: function(data){ 
                                $('#modal_2').modal('hide');                                                      
                            }
                 })   
         })    
    })

В этом модальном, который откроется, есть кнопка, чтобы вызвать другой модальный, нажав этотКнопка запускает новый вызов Ajax, чтобы открыть новый модал.Когда я закрываю modal_2, modal_1 теряет scrool и больше невозможно прокручивать страницу.Я много думал о Модале поверх Модала, но я не нашел ничего, что использует Jquery (Ajax) и что модальное содержимое достаточно велико для прокрутки страницы и что на него влияет модальное верхнее

1 Ответ

0 голосов
/ 31 декабря 2018

https://dotnetfiddle.net/2q6mp1 Вы можете сделать это в PHP.

Так будет выглядеть ваш взгляд.Я добавляю ссылку .NET Fiddle выше.

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Tut139</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#btn_open_modal1").click(function () {
                $('#exampleModal').modal('show');

            })

            $("#btn_open_modal2").click(function () {
                $('#exampleModa2l').modal('show');

            })
        })
    </script>
</head>
<body>
    <!-- Button trigger modal -->
    <button id="btn_open_modal1" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
        Launch outer modal
    </button>

    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div style="height:50px; overflow-y: scroll;">
                        ...
                        does not lose its scroll
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                        Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                        when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                        It has survived not only five centuries, but also the leap into electronic typesetting,
                        remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                        sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
                        Aldus PageMaker including versions of Lorem Ipsum.
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                        Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                        when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                        It has survived not only five centuries, but also the leap into electronic typesetting,
                        remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                        sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
                        Aldus PageMaker including versions of Lorem Ipsum.
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                        Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                        when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                        It has survived not only five centuries, but also the leap into electronic typesetting,
                        remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                        sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
                        Aldus PageMaker including versions of Lorem Ipsum.
                    </div>
                </div>
                <div class="modal-footer">
                    <button id="btn_open_modal2" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal2">
                        Launch second modal
                    </button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    ...
                    Close this second modal and first modal, still has scroll capabilities
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
...