web端打印,可以忽略部分内容不打印

    xiaoxiao2025-10-16  11

    <!--打印的实现1:start--> <input id="btnPrint" type="button" value="打印" οnclick="javascript:window.print();" /> <!--将不需要打印的部分,标记为 class="noprint" --> <style type="text/css" media=print> .noprint{display : none } </style> <div><p class="noprint">不需要打印的地方</p> <p>打印的部分</p></div> <!--打印的实现1:end--> ---------------------------------- <!--打印的实现2:start--> <input id="btnPrint" type="button" value="打印预览" οnclick=preview(1) /> <script> function preview(oper)        { if (oper < 10) { bdhtml=window.document.body.innerHTML;//获取当前页的html代码 sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域 eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域 prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html window.document.body.innerHTML=prnhtml; window.print(); window.document.body.innerHTML=bdhtml; } else { window.print(); } } </script> <p>XXXXX</p> <!--startprint1-->要打印的内容<!--endprint1--> 再加个打印按纽 οnclick=preview(1)  <!--打印的实现2:end-->
    转载请注明原文地址: https://ju.6miu.com/read-1303198.html
    最新回复(0)