This article mainly introduces JS or jquery how to achieve page printing can also be local printing, the need for friends can refer to the following
JS or jquery to achieve page printing (local printing) 1, JS implementation (can achieve local printing) code as follows: <html> <title>js printing </title > <head></head><body> <input id= "btnprint" type= button "value=" Print "onclick=" Javascript:window.print (); "/> <input id=" btnprint "type=" button "value=" Print Preview "Onclick=preview (1)/ > <style type= "text/css" media=print> noprint{display:none} </style> & nbsp <p class= "noprint" > do not need to print where </p> <script> function Preview (oper) { if (Oper <) { bdhtml=window.document.body.innerhtml;//get the HTML code for the current page sprnstr= "<!--startprint" +oper+ "-->"//Set Print start area eprnstr= "<!--endprint" +oper+ "-->";//Set Print End area prnhtml= Bdhtml.substring (Bdhtml.indexof (SPRNSTR) +18); Take the html prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR)) backward from the start code;//forward from the end code html window.document.body.innerhtml=prnhtml; WINdow.print (); window.document.body.innerhtml=bdhtml; } else { window.print (); } } </script> <p>XXXXX</p> <!--startprint1--> What to print <!--endprint1--> </body> </html> 2, call Windows bottom Print, report security Warning, not recommended (do not support local printing) code is as follows: <HTML> <HEAD> <title>javascript Print-print page setup-print Preview code </TITLE> <meta Http-equiv=content-type Content= "text/html; charset=gb2312 "/> <script language=javascript> function Printsetup () { //print Page Setup WB . EXECWB (8,1); } function PrintPreview () { //print page preview WB.EXECWB (7,1); } function printit () { if (Confirm (' OK to print?) ') { WB.EXECWB (6,6); } } </SCRIPT> </HEAD> <BODY> &nb Sp <div align=center> <object ID=WB height=0 width=0&nbSp CLASSID=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></object> <INPUT Onclick=javascript: PrintIt () Type=button value= print name=button_print/> <input onclick=javascript:printsetup (); Type=button value= Print Page Setup name=button_setup/> <input onclick=javascript:printpreview (); Type=button value= Print Preview Name=button_show/> a start weight loss card time period </DIV> </BODY> </ html> 3, jquery implementation (support for local printing) code as follows: <html> <head> <script type= " Text/javascript "src=" Jquery-1.6.4.js "></script> <script> $ (function () { $ (" input# Biuuu_button "). Click (function () { $ (" Div#myprintarea "). PrintArea (); }); </script> </head> <body> <input id= "Biuuu_button" type= "button" value= "Print" ></input> <div id= "Myprintarea" ... Text Print section .....</div> <div class= "Quote_title" > References </div><div class= "Quote_div" ></div> </body> </html>