Print a div content using Jquery

前端 未结 13 2083
栀梦
栀梦 2020-11-30 05:22

I want to print the content of a div using jQuery. This question is already asked in SO, but I can\'t find the correct (working) answer.

This is is my HTML:

相关标签:
13条回答
  • 2020-11-30 06:16
    <div id='printarea'>
        <p>This is a sample text for printing purpose.</p> 
    </div>
    <input type='button' id='btn' value='Print' onlick="printDiv()">
    <p>Do not print.</p>
    
    function printDiv(){
            var printContents = document.getElementById("printarea").innerHTML;
            var originalContents = document.body.innerHTML;
            document.body.innerHTML = printContents;
            window.print();
            document.body.innerHTML = originalContents;
    }
    

    This Above function should be load on same page.

    0 讨论(0)
提交回复
热议问题