在很多客户请求中,有些字据要进行打印,比如一些发票或一些具体的详情信息需要打印。具体直接上代码:
页面代码:
<div class="modal fade" >
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="background-color:#99cadb; ">
<div class="modal-header" style="background-color: #99cadb;" >
<button class="btn btn-sm btn-primary" ng-click="doPrintdetail()"> 打印数据</button>
<button type="button" class="close"
data-dismiss="modal" aria-hidden="true">
×
</button>
</div>
<!--startprint-->
<div class="modal-dialog">
<div class="modal-content">
<h2 class="modal-title" >
详情信息
</h2>
<div class="modal-body">
<table>
<tr><td></td><td>商户ID</td><td></td>
<td >{{currentCoupons.merchantRoleId}}</td></tr>
<tr><td></td><td">优惠券类型</td><td></td>
<td >免费{{currentCoupons.freeTime}}小时</td>
<td >免费{{currentCoupons.money}}元</td>
<td >全额免费</td>
<td >最大免费时长</td>
</tr>
</table>
</div>
</div>
</div>
<!--endprint-->
</div>
</div>
</div>
<!--startprint--> <!--endprint--> 一定要填写的,这是标志文件打印的起始。
js代码:
$scope.doPrintdetail=function() { bdhtml=window.document.body.innerHTML; sprnstr="<!--startprint-->"; eprnstr="<!--endprint-->"; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); OpenWindow = window.open(""); //OpenWindow.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/parkmanage-new/css/printdetail.css\">"); OpenWindow.document.body.innerHTML=prnhtml; OpenWindow.print(); };