JS调用打印机功能简单示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JS调用打印机功能简单示例

巴霍巴利   2020-05-15 我要评论

本文实例讲述了JS调用打印机功能的方法。分享给大家供大家参考,具体如下:

<!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><!--{$aListData.name}-->准考证</title>
<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>
<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
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
</script>
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script>
jQuery(function($){
 $("#closeButton").click(function(){
    window.close();
 })
});
</script>
</head>
<body>
<a id='closeButton' title='Close' href="#" >关闭</a>
<!-- 打印startprint与endprint之间的内容-->
<!--startprint1-->
<h1>南京聋人高级中学2013年预科招生考试</h1>
姓名:<!--{$aListData.name}--><br/>
性别:<!--{$aListData.gender}--><br/>
毕业学校:<!--{$aListData.grschool}--><br/>
编号:<input type="text" name="sturegcard" class="input1 ml10" value="<!--{$aListData.sturegcard}-->"/><br/>
头像:<img src="<!--{$aListData.avatar}-->" width="140"><br/>
考试日程:<br/>
地点:<br/>
<!--{if $aRegExamsche}-->
  <!--{section name=data loop=$aRegExamsche}-->
    <!--{$aRegExamsche[data].date}-->
    <!--{$aRegExamsche[data].time}-->
    <!--{$aRegExamsche[data].lesson}-->
    <!--{$aRegExamsche[data].place}--><br/>
  <!--{/section}-->
<!--{/if}-->
<!--endprint1-->
</body>
</html>

希望本文所述对大家JavaScript程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们