歡迎來(lái)到奇迪科技(深圳)有限公司,超值服務(wù)提供卓越產(chǎn)品!
網(wǎng)站制作之設定只打印指定的內容_Html教程_奇迪科技(深圳)有限公司(m.cheanjie.com)
很多時(shí)候,我們需要設定打印程序只需打印一個(gè)頁(yè)面的某些內容,而不是全部。這個(gè)時(shí)候,我們就需要在網(wǎng)站制作,設計頁(yè)面前框架的時(shí)候,就需要考慮好,我們需要打印的內容是這個(gè)頁(yè)面的哪一部分?以下提供兩種方案供您參考:
方案一:
<!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>網(wǎng)站制作之設定只打印指定的內容</title> </head> <body> <!--startprint--> 只有這里面的內容會(huì )被打印機打印出來(lái) <!--endprint--> <script> <!-- function preview() { 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> <!--打印按鈕--> <button onClick="preview()">【我要打印】</button> </body> </html>
方案2:
<!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>網(wǎng)站制作之設定只打印指定的內容</title> </head> <body> <div id="printCon"> 打印的時(shí)候,只會(huì )打印這里面的內容。 </div> <!--打印按鈕--> <a href= "javascript:;" onclick= "printPage()">打印 </a> <script type="text/javascript" language="javascript"> <!-- function printPage(){ var newWin=window.open('about:blank', '', ''); var titleHTML=document.getElementById("printCon").innerHTML; newWin.document.write(titleHTML); newWin.document.location.reload(); newWin.print(); } //--> </script> </body> </html> </body> </html>
方案一和方案二所實(shí)現的功能是一樣的。如果您想知道其中卻別,可以自己測試一下。
本文版權所有,轉載須注明:來(lái)源 http://m.cheanjie.com/qvdv-wdl-98.html