Print DIV content by JQuery

前端 未结 6 857
无人共我
无人共我 2021-02-06 03:26

suppose i have many div\'s in my page but i want to print the content of specific div using jquery. i found there is a plugin for that.

jQuery Print Element

usin

6条回答
  •  礼貌的吻别
    2021-02-06 04:09

    Here is a JQuery&JavaScript solutions to print div as it styles(with internal and external css)

    $(document).ready(function() {
                $("#btnPrint").live("click", function () {//$btnPrint is button which will trigger print
                    var divContents = $(".order_summery").html();//div which have to print
                    var printWindow = window.open('', '', 'height=700,width=900');
                    printWindow.document.write('');
                    printWindow.document.write('');//external styles
                    printWindow.document.write('');
                    printWindow.document.write('');
                    printWindow.document.write(divContents);
                    printWindow.document.write('');
                    printWindow.document.close();
    
                    printWindow.onload=function(){
                    printWindow.focus();                                         
                    printWindow.print();
                    printWindow.close();
                    }
                });
    });
    

    This will print your div in new window.

    Button to trigger event

    
    

提交回复
热议问题