Bootstrap: Open Another Modal in Modal

后端 未结 21 970
难免孤独
难免孤独 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:48

    You can actually detect when the old modal closes by calling the hidden.bs.modal event:

        $('.yourButton').click(function(e){
            e.preventDefault();
    
            $('#yourFirstModal')
                .modal('hide')
                .on('hidden.bs.modal', function (e) {
                    $('#yourSecondModal').modal('show');
    
                    $(this).off('hidden.bs.modal'); // Remove the 'on' event binding
                });
    
        });
    

    For more info: http://getbootstrap.com/javascript/#modals-events

提交回复
热议问题