js調用小票打印機
佳博GP 3120熱敏打印機
- <!--打印的實現1:start-->
- <input id="btnPrint" type="button" value="打印" οnclick="javascript:window.print();" />
- <!--將不需要打印的部分,標記爲 class="noprint" -->
- <style type="text/css" media=print>
- .noprint{display : none }
- </style>
- <p class="noprint">不需要打印的地方</p>
- <p>打印的部分</p>
- <!--打印的實現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
- prnhtmlprnhtml=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-->