<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>js print打印网页指定区域内容的简单实例</title> </head> <script> function myprint(obj){ var newwindow=window.open("打印窗口","_blank"); var docstr = obj.innerhtml; newwindow.document.write(docstr); newwindow.document.close(); newwindow.print(); newwindow.close(); } </script> <div id="print"> <hr /> 打印演示区域,点击打印后会在新窗口加载这里的内容! <hr /> </div> <button onclick="myprint(document.getelementbyid('print'))">打 印</button> </html>
