查了一下网上的资料,找到一个比较合适的例子,做一个记录
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function preview0(){
window.print();
}
function preview(){
bdhtml = window.document.body.innerHTML;
sprnstr = "<!--start-->";
eprnstr = "<!--end-->";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr));
prnhtml = prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
}
</script>
<style media="print">
@page {
size: auto; /* auto is the initial value */
margin: 7mm; /* this affects the margin in the printer settings */
}
</style>
</head>
<body>
<form id="WebForm1" method="post" > <div>1234567890</div>
<!--start-->
<div align="center">
<center>本部分以上不被打印</center>
<table border="1">
<tr bordercolor="#FFFFFF" ;>
<th bordercolor="#FFFFFF">销售单</th>
<th>工资单</th>
</tr>
<tr>
<td>销售单</td>
<td>销售123</td>
</tr>
</table>
</div>
<!--end-->
<center>本部分以下不被打印</center>
<div align="center">
<input type="button" name="print" value="预览并打印" onClick="preview()">
</div>
</form>
</body>
</html>