close one modal and open a new modal with one butt

2019-04-01 01:11发布

问题:

I am using bootstrap and have a one modal that I would like to have a link on to another modal. I can't seem to figure this out and currently I am using the modal.close()and .modal('show') but that is not working.

$('a#to3heart').click(function(){
    $('#portfolioModal2').modal({onShow: function (dialog) {
        $.modal.close()
        $('#portfolioModal1').modal('show'); 
            return false;
        }
    });
});

回答1:

use:

$("#modal1").modal('hide');
$("#modal2").modal('show');

see: http://getbootstrap.com/javascript/#modals

demo: http://jsfiddle.net/5qCm9/



回答2:

I had a similar issue and solved it with a generic jQuery solution.

It just hides all modal that are not targeted.

$('button[data-target]').click(function () {
    $('.modal').not($(this).data('target')).modal('hide');
});