weixin_33744854 2018-12-31 19:43 采纳率: 0%
浏览 10

使用jQuery的模态

I need to open a modal on another modal, the problem is that the first modal loses the scrool bar of the main page after closing the modal that is on it.

I'll try to explain better:

I have this modal which loads in the modal-body a content that can be extensive coming from a query in 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>

I load the information to be displayed in the modal-body in the following Jquery action:

$(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');   
        }
      })
})

In this modal that will open has a button to call another modal

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

In this modal that will open has a button to call another modal clicking this button launches a new Ajax call to open a new modal

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

and in 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');                                                      
                            }
                 })   
         })    
    })

In this modal that will open has a button to call another modal clicking this button launches a new Ajax call to open a new modal. When I close modal_2, modal_1 loses scrool and it is no longer possible to scroll the page. I skidded a lot about Modal over Modal, but I did not find anything that uses Jquery (Ajax) and that the modal content is large enough to scroll the page and that it is influenced by the modal upper

  • 写回答

1条回答 默认 最新

  • 三生石@ 2018-12-31 20:39
    关注

    https://dotnetfiddle.net/2q6mp1 You can do this in PHP.

    This is what your view will look like. I am adding a .NET Fiddle link above.

    <!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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛