介绍一个简单的打印机打印方法
最近在项目中做到打印机的打印功能,虽然很简单,但还是分析下:
<div class="controltitle">当前操作:信息管理——>学生信息列表-->学生信息的打印</div> <span class="content_button_a_left" onclick="printdiv('div_print');">打印</span> <div id = "div_print"> <table class="tablefirst" id="radioSub"> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <col style="width:5%"/> <tr> <th>学号</th><th>姓名</th><th>性别</th><th>专业</th><th>学制</th><th>入学年份</th><th>毕业年份</th><th>工作省市</th><th>工作单位</th><th>岗位</th><th>职称</th> <th>办公电话</th><th>手机号</th><th>QQ</th><th>电子邮箱</th><th>通信地址</th><th>家庭地址</th> </tr> <#if inforList?exists> <#list inforList as infor> <tr> <td>${infor.stuNum}</td> <td>${infor.stuName}</td> <td>${infor.stuSex}</td> <td>${infor.stuZy}</td> <td>${infor.stuXz}</td> <td>${infor.stuStartTime}</td> <td>${infor.stuEndTime}</td> <td>${infor.stuWorkAddress}</td> <td>${infor.stuWorkPlace}</td> <td>${infor.stuWorkPost}</td> <td>${infor.stuWorkZc}</td> <td>${infor.stuPhone}</td> <td>${infor.stuTelephone}</td> <td>${infor.stuQq}</td> <td>${infor.stuEmail}</td> <td>${infor.stuCommAddress}</td> <td>${infor.stuAddress}</td> </tr> </#list> </#if> </table> </div> <div class="shadeHiddenBlock" id="subDetail" style="dispaly:none;"></div> <script> function printdiv(printpage){ var headstr = "<html><head><title></title></head><body>"; var footstr = "</body></html>"; var newstr = document.all.item(printpage).innerHTML; var oldstr = document.body.innerHTML; document.body.innerHTML = headstr+newstr+footstr; window.print(); document.body.innerHTML = oldstr; return false; } </script>
其实打印操作就是调用一段js代码,将特定的div中的内容进行打印,该方法很简单
希望多多交流,多多关注,共同成就梦想