How can I insert a Print button that prints a form in a webpage

后端 未结 3 1453
耶瑟儿~
耶瑟儿~ 2020-12-13 07:20

So, lets say I got a simple form inside a page like this:

STUFF

相关标签:
3条回答
  • 2020-12-13 07:32

    To print with submit button, add this to your summit script:

    <input type="button" value="Print this page" onClick="window.print()">

    Keep in mind, this will only trigger whatever browser implemented print capabilities are available at the client.

    0 讨论(0)
  • 2020-12-13 07:33

    What you need is the window.print():

    <form style="text-align:center;">
    
      <p> STUFF </p>
    
      <a href="#" id="lnkPrint">Print</a>
    </form>
    

    Javascript:

    $( document ).ready(function() {
        $('#lnkPrint').click(function()
         {
             window.print();
         });
    });
    
    0 讨论(0)
  • 2020-12-13 07:45

    Print whole page

    Try adding a button that calls window.print()

    <input type="button" value="Print this page" onClick="window.print()">
    

    Print a specific portion/container in a page

    <div id="print-content">
     <form>
    
      <input type="button" onclick="printDiv('print-content')" value="print a div!"/>
    </form>
    </div>
    

    then in HTML file add this script code

    <script type="text/javascript">
        function printDiv(divName) {
            var printContents = document.getElementById(divName).innerHTML;
            w=window.open();
            w.document.write(printContents);
            w.print();
            w.close();
        }
    

    Refer Print <div id="printarea"></div> only?

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