码迷,mamicode.com
首页 > 其他好文 > 详细

使用打印机分页打印订单

时间:2015-10-10 15:25:33      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<head>

<script language="javascript">
function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
//var newstr = document.all.item(printpage).innerHTML;
var newstr = document.getElementById(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}
</script>
<title>div print</title>
</head>

<body>
//HTML Page
//Other content you wouldn‘t like to print
<input name="b_print" type="button" class="ipt"   onClick="printdiv(‘div_print‘);" value=" Print ">

<div id="div_print">

<h1 style="Color:Red">The Div content which you want to print</h1>
<div  style="page-break-before:always;"><br /></div>
<h1 style="Color:Red">The Div content which you want to print</h1>
<div  style="page-break-before:always;"><br /></div>
</div>
//Other content you wouldn‘t like to print
//Other content you wouldn‘t like to print
</body>

</html>

 原理:大家window.print()函数可以打印网页,但是通常我们并不想打印整个页面的所有内容。这个时候就可以利用js取到原来整个页面的内容,和需要打印的区域(div)的内容,然后运行函数,将页面替换成只有div中的内容,执行print()函数,然后再将页面还原。

控制分页只需要这一条语句:<div style="page-break-before:always;"><br /></div>

使用打印机分页打印订单

标签:

原文地址:http://www.cnblogs.com/doubilaile/p/4866838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!