php 實現打印預覽的功能


<inputid="btnPrint" type="button" value="打印"onclick="javascript:window.print();" />
<inputid="btnPrint" type="button" value="打印預覽" onclick=preview(1)/>
<styletype="text/css" media=print>
.noprint{display : none}
</style>
<pclass="noprint">不須要打印的地方</p>
<script>
functionpreview(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–>
<inputid="btnPrint" type="button" value="打印"onclick="javascript:window.print();" />
<inputid="btnPrint" type="button" value="打印預覽" onclick=preview(1)/>
<styletype="text/css" media=print>
.noprint{display : none}
</style>
<pclass="noprint">不須要打印的地方</p>
<script>
functionpreview(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–>


免責聲明!

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



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