close one modal and open a new modal with one button

北城余情 提交于 2019-12-05 02:13:52

问题


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


来源:https://stackoverflow.com/questions/25098967/close-one-modal-and-open-a-new-modal-with-one-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!