Twitter Bootstrap: Print content of modal window

前端 未结 10 985
走了就别回头了
走了就别回头了 2020-11-28 02:19

I\'m developing a site using Bootstrap which has 28 modal windows with information on different products. I want to be able to print the information in an open modal window.

10条回答
  •  清酒与你
    2020-11-28 02:39

    I just use a bit of jQuery/javascript:

    html:

    Don't Print

    Launch modal

    js:

    $('#printButton').on('click', function () {
        if ($('.modal').is(':visible')) {
            var modalId = $(event.target).closest('.modal').attr('id');
            $('body').css('visibility', 'hidden');
            $("#" + modalId).css('visibility', 'visible');
            $('#' + modalId).removeClass('modal');
            window.print();
            $('body').css('visibility', 'visible');
            $('#' + modalId).addClass('modal');
        } else {
            window.print();
        }
    });
    

    here is the fiddle

提交回复
热议问题