dsfphczao23473056 2018-10-10 15:05 采纳率: 100%
浏览 199
已采纳

在PHP中提交按钮后打印帐单发票

I have two columns item name and amount. I just click the submit button and then I want to print the invoice. I already set the invoice format and I know onclick="window.print() but in this case the page prints everything. I only want to print the invoice format after the submit button.

<form method="post">
item name
<input type="text" name="item">
amount
<input type="text" name="amt">
<input type="submit" name="submit">

</form>
<?php
if(isset($_POST['submit'])){

    $item = $_POST['item']  ;
    $amt = $_POST['amt']  ;


    // want print I have set the invoice

    }

?>
  • 写回答

1条回答 默认 最新

  • dongtiaozhou4914 2018-10-10 15:09
    关注

    You should use JavaScript instead of php. Please put the printing part inside a div with an id As:

    <div id="print_setion">
          <h1>Print This Setion Only</h1>
    </div>
    
    <input type="button" onclick="printDivSection('print_setion')" value="Print This Setion Only" />
    

    and create JavaScript as :

    function printDivSection(setion_id) {
         var Contents_Section = document.getElementById(setion_id).innerHTML;
         var originalContents = document.body.innerHTML;
    
         document.body.innerHTML = Contents_Section;
    
         window.print();
    
         document.body.innerHTML = originalContents;
    }
    

    Note: innerHTML get only div section that is inside id <div id="print_setion">

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用