<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
//打印代码
function Print()
{
var printStr = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body >";
var content = "";
var str = document.getElementById('page1').innerHTML; //获取需要打印的页面元素 ,page1元素设置样式page-break-after:always,意思是从下一行开始分页。
content = content + str;
str = document.getElementById('page2').innerHTML; //获取需要打印的页面元素
content = content + str;
printStr = printStr+content+"</body></html>";
var pwin=window.open("Print.htm","print"); //如果是本地测试,需要先新建Print.htm,如果是在域中使用,则不需要
pwin.document.write(printStr);
pwin.document.close(); //这句很重要,没有就无法实现
pwin.print();
}
</script>
</head>
<body >
<div><input type="button" value="打印" onclick="Print()" /></div>
<div id="page1">
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="content" style="page-break-after:always" >
<tr><td>第一页打印内容</td></tr>
</table>
</div>
<div id="page2">
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="content" >
<tr><td>第二页打印内容</td></tr>
</table>
</div>
</body>
</html>
JS 实现web分页打印功能
3星 · 超过75%的资源 需积分: 48 106 浏览量
2015-11-09
20:40:27
上传
评论 4
收藏 2KB RAR 举报
爱跳舞的铅笔头
- 粉丝: 324
- 资源: 55
最新资源
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
- 健身房系统的设计与实现论文Java项目
- 使用TCP实现的搜索可用服务器
- 使用贪心算法解决会议时间安排问题的 Java 示例代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈