您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何使用JS实现分页打印

2024/4/22 15:36:45发布14次查看
这次给大家带来如何使用js实现分页打印,使用js实现分页打印的注意事项有哪些,下面就是实战案例,一起来看一下。
在调用window.print()时,可以实现打印效果,但内容太多时要进行分页打印。
在样式中有规定几个打印的样式
page-break-before和page-break-after css属性并不会修改网页在屏幕上的显示,这两个属性是用来控制文件的打印方式。
每个打印属性都可以设定4种设定值:auto、always、left和right。其中auto是默认值,只有在有需要时,才需设定分页符号 (page breaks)。
page-break-before若设定成always,则是在遇到特定的组件时,打印机会重新开始一个新的打印页。
page-break-before若设定成left,则会插入分页符号,直到指定的组件出现在一个左边的空白页上。
page-break-before若设定成right,则会插入分页符号,直到指定的组件出现在一个右边的空白页上。
page-break-after属性会将分页符号加在指定组件后,而非之前。
在下列程序中您将可以看到这些属性的设定,
<html> <head> <title>listing 14-4</title> </head> <body> <p>this is the first p.</p> <p style="page-break-before:always">this is the second p.</p> <p style="page-break-after:always">this is the third p.</p> <p>this is the fourth p.</p> <p style="page-break-before:right">this is the fifth p.</p> <p style="page-break-after:right">this is the sixth p.</p> <p>this is the last p.</p> </body> </html>
值 描述
auto 默认值。如果必要则在元素前插入分页符
always 在元素前插入分页符
avoid 避免在元素前插入分页符
left 在元素之前足够的分页符,一直到一张空白的左页为止
right 在元素之前足够的分页符,一直到一张空白的右页为止
inherit 规定应该从父元素继承 page-break-before 属性的设置
在dom对象中pagebreakbefore属性
语法:
object.style.pagebreakbefore=auto|always|avoid|left|right
<html> <head> <script type="text/javascript"> function setpagebreak() { document.getelementbyid(p2).style.pagebreakbefore=always; } </script> </head> <body> <p>this is a test paragraph.</p> <input type="button" onclick="setpagebreak()" value="set page-break" /> <p id="p2">this is also a test paragraph.</p> </body> </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
如何处理mac安装thrift因bison报错
如何正确处理淘宝cnpm安装后cnpm不是内部或外部命令
以上就是如何使用js实现分页打印的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product