网页打印代码

tech2022-10-25  62

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button type="button" onclick="doPrint()">打印</button></div> <div> 哈哈 </div> <script type="text/javascript"> function doPrint() { alert(66666666666); 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(); window.document.body.innerHTML=bdhtml;//重新给页面内容赋值; return false; } </script> </body> </html>

 

最新回复(0)