1 <script language=javascript>
2 function doPrint() {
3 bdhtml=window.document.body.innerHTML;
4 sprnstr= " <!--startprint--> ";
5 eprnstr= " <!--endprint--> ";
6 prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
7 prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
8 window.document.body.innerHTML=prnhtml;
9 window.print();
10 }
11 </script>
2、在页面正文处加上 <!--startprint--> 与 <!--endprint--> 标识。也就是在需要用户打印保存的正文所对应的html处附加上。2 function doPrint() {
3 bdhtml=window.document.body.innerHTML;
4 sprnstr= " <!--startprint--> ";
5 eprnstr= " <!--endprint--> ";
6 prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
7 prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
8 window.document.body.innerHTML=prnhtml;
9 window.print();
10 }
11 </script>
3、截取内容部分已完成,现在加个“打印”的链接: <a href= "javascript:; " onClick= "doPrint() "> 打印教程 </a>