Back

一段打印程序

发布时间: 2018-04-04 07:32:00

参考:  https://stackoverflow.com/questions/2255291/print-the-contents-of-a-div#answer-2255438

function my_print(id)
{
    var mywindow = window.open('', 'PRINT', 'height=800,width=1000');

    mywindow.document.write('<html><body>');
    mywindow.document.write(document.getElementById(id).innerHTML);
    mywindow.document.write('</body></html>');

    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10*/

    mywindow.print();
    mywindow.close();

    return true;
}

然后,只要你有个区域是用来打印的:<div id="print_area"></div>

就可以直接调用了. 

Back