简单的html打印

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>打印票据</title>
<script  type="text/javascript">
function doPrint(){
var bdhtml=window.document.body.innerHTML;
var sprnstr="<!--startprint-->";
var eprnstr="<!--endprint-->";
prnhtml
=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml
=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML
=prnhtml;
window.print(); }
</script></head>
<body style="font-size:12px;margin-left:2px">
<!--startprint-->要打印的内容,可以自由控制<!--endprint--><input type="button" value="打印票据" id="print" onClick="doPrint()">
</body>
</html>
posted @ 2009-11-13 09:45  麦兜很乖  阅读(391)  评论(0编辑  收藏  举报