代碼如下,簡單實用。因為需要用到這個東西,所以很無恥的拾人牙慧,收藏一下。
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</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--><!--注意要加上html里star和end的這兩個標記,之前沒加,一直沒效果,誰叫咱們菜呢~--><h1>打印標題</h1><p>打印內容~~</p><!--endprint--><button type="button" onclick="doPrint()">打印</button><p>1</p><p>2</p></body></html>
以上就是本文的全部內容,了解更多JavaScript的語法,大家可以查看:《JavaScript 參考教程》、《JavaScript代碼風格指南》,也希望大家多多支持武林網。
|
新聞熱點
疑難解答