Js打印

时间:2014-05-09 00:01:06   收藏:0   阅读:403
bubuko.com,布布扣
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus?">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js">
</script>

<input id="btnPrint" type="button" value="打印" onclick="javascript:window.print();" />  
<input id="btnPrint" type="button" value="打印预览" onclick="preview(1)" />  
<style type="text/css" media="print">  
.noprint{display : none }  
</style>  
  
  
<p class="noprint">不需要打印的地方</p>  
  
<script>  
function preview(oper)         
{  
if (oper < 10)  
{  
bdhtml=window.document.body.innerHTML;//获取当前页的html代码  
sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域  
eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域  
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html  
  
prnhtmlprnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html  
window.document.body.innerHTML=prnhtml;  
window.print();  
window.document.body.innerHTML=bdhtml;  
} else {  
window.print();  
}  
}  
</script>  
<p>要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容</p>  
</body>
</html>
bubuko.com,布布扣

 

Js打印,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!