1、页面元素:
<body style="width: 100%;height: 100%">
<!--startprint-->
<div id="picView" style="width:90%; height:90%;text-align: center; border: 2px">
<input type="hidden" id="imageVal" name="imageVal" value="${imageVal}">
<img id="imageView" width="60%" height="80%"/>
</div>
<!--endprint-->
<input type="button" value="打印" onclick="doPrint()" />
</body>
2、js:
<script type="text/javascript">
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
3、注释:
将需要打印的页面内容包在<!--startprint--><!--endprint-->之间即可!