打印body裏面的內容
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();
}
}
html中添加
<a href="javascript:preview(1);"></a>
有時候打印是空白的不知道爲什麼