The code is as follows, simple and practical. Because I need to use this thing, I shamelessly pick up people's teeth and save it.
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Unt titled document</title><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></head> <body><p>1</p><p>2</p><!--startprint--><!--note that the two marks of star and end in html are added. They have not been added before and have no effect. Who told us to do it~--><h1>Print the title</h1><p>Print the content~~</p><!--endprint--><button type="button" onclick="doPrint()">Print</button><p>1</p><p>2</p></body></html>The above is the entire content of this article. For more information about JavaScript, you can check out: "JavaScript Reference Tutorial" and "JavaScript Code Style Guide". I also hope that everyone will support Wulin.com more.