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">

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

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码