js控制打印html頁面


加入以下js代碼

<script language="javascript">

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>

把需要打印的頁面放入以下標簽中

<!--startprint1-->

<!--打印內容開始-->

<div> 打印的內容 </div>

<!--打印內容結束-->

<!--endprint1-->

然后就差一個點火設備了,我們就可以一起裝逼一起飛

<input type=button name='button_export' onclick=preview(1) value="我只是個打印按鈕而已">


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM