<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>打印预览</title>
<style>
.product {
margin-left: 85px;
}
</style>
</head>
<body>
<!--startprint-->
<p>订单编号:D47328947239847239</p>
<p>订单金额:104.50 元</p>
<p>订单时间:2019-10-08 19:50</p>
<p>订单产品:</p>
<p class="product">红烧毛豆 3.50元 × 1</p>
<p class="product">爆炒豆腐 5.50元 × 2</p>
<p class="product">干瘪烤鸭 9.00元 × 10</p>
<!--endprint-->
<input type="button" onclick="printingPreview();" class="btn" value="打印预览" />
<script>
function printingPreview() {
bdhtml = window.document.body.innerHTML;
sprnstr = '<!--startprint-->';
eprnstr = '<!--endprint-->';
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17); //17Ϊsprnstr��length
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
location.reload();
}
</script>
</body>
</html>
JS打印预览
猜你喜欢
转载自blog.csdn.net/u013727805/article/details/102408806
今日推荐
周排行