Bootstrap: Open Another Modal in Modal

后端 未结 21 1015
难免孤独
难免孤独 2020-11-27 11:28

So, I\'m using this code to open another modal window in a current opened modal window:



        
21条回答
  •  悲哀的现实
    2020-11-27 11:41

    My solution does not close the lower modal, but truly stacks on top of it. It preserves scrolling behavior correctly. Tested in Bootstrap 3. For modals to stack as expected, you need to have them ordered in your Html markup from lowest to highest.

    $(document).on('hidden.bs.modal', function (event) {
      if ($('.modal:visible').length) {
        $('body').addClass('modal-open');
      }
    });

    UPDATE: When you have stacked modals, all the backdrops appear below the lowermost modal. You can fix that by adding the following CSS:

    .modal-backdrop {
        visibility: hidden !important;
    }
    .modal.in {
        background-color: rgba(0,0,0,0.5);
    }
    

    This will give the appearance of a modal backdrop below the topmost visible modal. That way it grays out your lower modals underneath.

提交回复
热议问题