在页面中引入
<script>
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 =document.getElementById("mainbody").innerHTML;
//window.print();
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml;
}
</script>
在需要打印的地方,比如table
<!--startprint-->
<table>
</table>
<!--endprint-->
<input type="button" onclick="doPrint()" value="打印"/>
就会打印table中的内容