Js打印页面指定内容
来源:互联网 发布:手机淘宝安卓版 编辑:程序博客网 时间:2024/04/30 10:45
一、主要代码
1、js代码
1
2
3
4
5
6
7
8
9
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
2、html代码
在需要打印的地方用<!–startprint–><!–endprint–>包裹
二、截图
三、实例代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<head>
<style>
* { margin:0px; padding:0px; }
body {
background:#FAFAFA;
color: #303030;
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
font-size: 13px;
line-height: 18px;
text-align:center;
}
table {
background:#fff;
border-right:1px solid #ddd;
border-bottom:1px solid #ddd;
border-collapse: separate;
border-spacing: 0;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);
width:800px;
margin:0 auto;
margin-top:50px;
}
tr { border:1px solid #DDDDDD; font-size: 13px; }
th,td { border-top:1px solid #ddd; border-left:1pxsolid #ddd; padding:8px; }
th {
background: linear-gradient(center top , #F6F6F6, #EEEEEE) repeat scroll 0 0 rgba(0, 0, 0, 0);
background:-moz-linear-gradient(center top , #F6F6F6, #EEEEEE) repeat scroll 0 0 rgba(0, 0, 0, 0);
background:-webkit-gradient(linear, left top, left bottom, from(#f6f6f6), to(#eee));
text-align:left;
text-shadow: 0 1px 0 #FFFFFF;
}
button { margin-top:20px; width:100px; height:30px; }
</style>
</head>
<body>
<!--startprint-->
<table class="datatable">
<thead>
<tr>
<th># ID</th><th> Name</th><th>Age</th> <th>Email</th><th>Url</th>
</tr>
</thead>
<tr>
<td>1</td><td>Gonzo the Great</td><td>20</td><td>test@qq.com</td><td>http://www.52wulian.org</td>
</tr>
<tr>
<td>1</td><td>Gonzo the Great</td><td>20</td><td>test@qq.com</td><td>http://www.52wulian.org</td>
</tr>
<tr>
<td>1</td><td>Gonzo the Great</td><td>20</td><td>test@qq.com</td><td>http://www.52wulian.org</td>
</tr>
<tr>
<td>1</td><td>Gonzo the Great</td><td>20</td><td>test@qq.com</td><td>http://www.52wulian.org</td>
</tr>
<tr>
<td>1</td><td>Gonzo the Great</td><td>20</td><td>test@qq.com</td><td>http://www.52wulian.org</td>
</tr>
</table>
<!--endprint-->
<button onclick=doPrint();>Print</button>
<script>
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
</body>
</html>
欢迎转载,请注明转自:我爱物联网(http://www.52wulian.org)
本文链接: Js打印页面指定内容
- Js打印页面指定内容
- js打印页面指定内容
- JS简单方法打印页面指定内容
- js打印页面指定区域内容
- JS打印指定内容
- JS打印页面内容
- 指定页面内容的打印
- jquery 打印页面指定内容
- JS打印指定内容(新窗口)
- JS打印指定区域内容
- JS打印指定区域内容
- js 打印页面局部内容
- JavaScript打印页面的指定内容
- 页面中打印指定的内容
- js网页打印指定区域内容
- js打印div指定区域内容
- js调用打印机打印指定内容
- js print打印网页指定区域内容
- java中接口的定义与实现
- Mac OSX下破解软件的一般方法及过程
- Java调用外部命令
- 黑马程序员 Tansact——sql变量
- NSObject:类与协议
- Js打印页面指定内容
- 虚拟盘符注册表项修改项
- ubuntu下编译安装openocd配合JLINK调试
- 调用函数的方式决定了调用的上下文中的this值
- 划分树几道题目
- Myeclipse下安装Ext-js插件(亲测)
- shell -e -d等参数说明
- Linux之fdisk -l命令
- Tomcat 启动时出现java.io.EOFException