Open a Modal from another modal and close the first (launching) modal

后端 未结 6 2140
陌清茗
陌清茗 2020-12-24 09:42

I\'m using Bootstrap Modal Window plugin its work fine but i would like to open another model window when i click next and close first one. how can i do it?

         


        
6条回答
  •  暖寄归人
    2020-12-24 10:03

    Here is a recipe that lets you link two modals together in a general way. The first modal has a button that launches the second modal. When the second modal is closed the first modal is reopened.

    // Prevent modal on top of modal while maintaining dismissibility. 
    // If a sub-modal is dismissed the original modal is reopened.
    $('.modal [data-toggle="modal"]').on('click', function() {
      var curModal = $(this).closest('.modal');
      var nextModal = $($(this).attr('data-target'));
    
      if (curModal != nextModal) {
        curModal.modal('hide');
        nextModal.on('hide.bs.modal', function() {
          curModal.modal('show');
        });
      }
    });
    

    Note: This should only be used if you have at most 2 linked modals. Button on the second modal opening a third would cause unexpected behavior as it would close the second modal, open the third, and reopen the first as well.

提交回复
热议问题