/*這裏主要是去除頁眉和頁腳*/
<style type="text/css">
@page{
margin-top: 1mm;
margin-bottom: 1mm;
}
</style>
/*調用瀏覽器的打印方法*/
<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>
下面是頁面html中加入的代碼
<!--startprint1-->
<!--打印內容開始-->
<b>這裏隨便寫</b>
<!--打印內容結束-->
<!--endprint1-->
<input type=button name='button_export' title='打印1' onclick=preview(1) value=打印1>