JS 實現簡單的頁面局部打印例子

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();     } } 使用很簡單 將頁面內要打印的內容加入中間 <!--startprint1--> 這是打印的內容 <!--endprint1--> 再加個打印按紐 onclick=preview(1)
相關文章
相關標籤/搜索