Js通過window.print();實現列印
阿新 • • 發佈:2018-11-30
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>消費記錄PDF</title> <script type="text/javascript"> function doPrint() { bdhtml=window.document.body.innerHTML; sprnstr="<!--startprint-->"; eprnstr="<!--endprint-->"; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+10); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); window.document.body.innerHTML=prnhtml; window.print(); } </script> </head> <body> <!--startprint--><!--注意要加上html裡star和end的這兩個標記--> <div> <table style="border: #F0F8FF 1px solid"> <tr> <td style="width: 300px;height: 25px;background-color: #FF4500;">使用者名稱稱:</td> <td style="width: 300px;height: 25px;background-color: #FF4500;">蕭薰兒</td> </tr> <tr> <td style="width: 300px;height: 25px;background-color: #FF4500;">客戶型別:</td> <td style="width: 300px;height: 25px;background-color: #FF4500;">SVIP</td> </tr> <tr> <td style="width: 300px;height: 25px;background-color: #FF4500;">本次消費金額:</td> <td style="width: 300px;height: 25px;background-color: #FF4500;">6000.00</td> </tr> <tr> <td style="width: 300px;height: 25px;background-color: #FF4500;">本次支付方式:</td> <td style="width: 300px;height: 25px;background-color: #FF4500;">移動支付</td> </tr> <tr> <td style="width: 300px;height: 25px;background-color: #FF4500;">本次消費時間:</td> <td style="width: 300px;height: 25px;background-color: #FF4500;">2018-11-30 17:00:00</td> </tr> </table> </div> <!--endprint--> <button type="button" onclick="doPrint()">列印</button> </body> </html>
轉自: