本文实例讲述了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>