【发布时间】:2015-10-06 16:34:31
【问题描述】:
父页面
<div class="row">
<div class="col-md-3">
link 1
link 2
link 3
.
.
.
</div>
</div>
<div class="col-md-9">
<div ng-view></div>
</div>
当链接被点击时,子页面将被加载到 ng-view>
<table class='table table-bordered'>
<tr>
<td>
this is my screen view
when user clicks a link in parent page
specific contentd loaded here
</td>
</tr>
</table>
<button type="button" class="btn btn-success btn-md" ng-click="myprint()" >
<span class="glyphicon glyphicon-print"></span> Print
</button>
<div id ="printsection">
<table style="width:80mm;">
<tr style="text-align: center;">
<td>this is my print view contents
send these contents
to print to printer
</td>
</tr>
</table>
</div>
以上子页面有 2 个部分。屏幕视图和打印部分。
我希望当用户点击打印按钮时,打印部分内容发送到打印机。
我已经为媒体打印定义了这些 CSS 规则。
print.css
body {
background-color: white;
color: black;
font-family: Times,"Times New Roman",Garamond, serif;
}
body * {
visibility: hidden;
}
#printsection * {
visibility: visible;
}
#printsection {
position: absolute;
left: 0;
top: 0;
}
问题在于点击打印按钮,它隐藏了所有内容,甚至是打印部分。
我做错了什么?
请注意,我使用的是 80 毫米宽的 POS 打印机,我在打印部分制作的宽度 = 80 毫米。
【问题讨论】:
-
myprint() 例程怎么样?
-
我的打印例程是:$scope.myprint = function(){ window.print(); }
-
由于可见性继承,人们无法隐藏有趣部分之上的任何元素。上面与文档子节点深度一样,而不是视觉上。隐藏可打印文本所在容器中的所有其他部分,并隐藏任何没有可打印文本的容器。
标签: javascript html css angularjs