Home > Web Front-end > JS Tutorial > Simple example of JS calling printer function

Simple example of JS calling printer function

高洛峰
Release: 2016-12-03 16:36:11
Original
1573 people have browsed it

The example in this article describes how to call the printer function through JS. Share it with everyone for your reference, the details are as follows:

<!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=&#39;closeButton&#39; title=&#39;Close&#39; 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>
Copy after login


Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template