<html>
<head>
<title>打印</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<script type="text/javascript">
function printit(){
//将部分隐藏不打印
document.getElementById("no").style.display = "none";
window.print();
//部分还原回来
document.getElementById("no").style.display = "";
return false;
}
</script>
</head>
<body >
<form>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
</table>
<hr>
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧 打印分页实际是控制CSS而以..调用样式后自然分面打印了...
</td>
</tr>
</table>
<div id="no">
<input type=button value=打印分页 onclick="printit()">
</div>
</form>
</body>
</html>
<head>
<title>打印</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<script type="text/javascript">
function printit(){
//将部分隐藏不打印
document.getElementById("no").style.display = "none";
window.print();
//部分还原回来
document.getElementById("no").style.display = "";
return false;
}
</script>
</head>
<body >
<form>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
</table>
<hr>
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧 打印分页实际是控制CSS而以..调用样式后自然分面打印了...
</td>
</tr>
</table>
<div id="no">
<input type=button value=打印分页 onclick="printit()">
</div>
</form>
</body>
</html>
本文介绍了一种利用CSS样式实现网页分页打印的方法。通过设置特定的样式类,如.pageNext 和 .Noprint,并使用JavaScript控制这些样式的显示与隐藏,可以实现在打印时的自动分页效果。此外,还提供了一个简单的按钮来触发打印功能。
1892

被折叠的 条评论
为什么被折叠?



