js調用打印機服務

js調用小票打印機

佳博GP 3120熱敏打印機

 

  

  1. <!--打印的實現1:start-->  
  2.   
  3. <input id="btnPrint" type="button" value="打印" οnclick="javascript:window.print();" />  
  4.   
  5. <!--將不需要打印的部分,標記爲 class="noprint" -->  
  6. <style type="text/css" media=print>  
  7. .noprint{display : none }  
  8. </style>  
  9.   
  10. <p class="noprint">不需要打印的地方</p>  
  11.   
  12. <p>打印的部分</p>  
  13.   
  14.   
  15. <!--打印的實現1:end-->  
  16.   
  17.   
  18.   
  19.  
  20.   
  21.   
  22.   
  23.   
  24. <!--打印的實現2:start-->  
  25.   
  26. <input id="btnPrint" type="button" value="打印預覽" οnclick=preview(1) />  
  27. <script>  
  28. function preview(oper)         
  29. {  
  30. if (oper < 10)  
  31. {  
  32. bdhtml=window.document.body.innerHTML;//獲取當前頁的html代碼  
  33. sprnstr="<!--startprint"+oper+"-->";//設置打印開始區域  
  34. eprnstr="<!--endprint"+oper+"-->";//設置打印結束區域  
  35. prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //從開始代碼向後取html  
  36. prnhtmlprnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//從結束代碼向前取html  
  37. window.document.body.innerHTML=prnhtml;  
  38. window.print();  
  39. window.document.body.innerHTML=bdhtml;  
  40. } else {  
  41. window.print();  
  42. }  
  43. }  
  44. </script>  
  45.   
  46. <p>XXXXX</p>  
  47.   
  48. <!--startprint1-->要打印的內容<!--endprint1-->  
  49.   
  50. 再加個打印按紐 οnclick=preview(1)   
  51.   
  52. <!--打印的實現2:end-->

 

 

 

發佈了11 篇原創文章 · 獲贊 30 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章