JavaScript 列印Web頁面指定地區的資訊

來源:互聯網
上載者:User
  1. <html >
  2. <head runat="server">
  3.     <title>無標題頁</title>    
  4.     <script type="text/javascript">      
  5.      function printdiv()
  6.     {
  7.         var headstr = "<html><head></head><body>";
  8.         var footstr = "</body>";
  9.         var newstr = document.getElementById("YesPrint").innerHTML;
  10.         var oldstr = document.body.innerHTML;
  11.         document.body.innerHTML = headstr+newstr+footstr;
  12.         window.print(); 
  13.         document.body.innerHTML = oldstr;
  14.         return false;
  15.     } 
  16.  
  17.     function okPrint()
  18.     {
  19.         if   (confirm("您確定要列印成文檔嗎?")==true)
  20.         {  
  21.              printdiv();
  22.         }
  23.         else
  24.         {
  25.              window.close();        
  26.         }
  27.     }  
  28.     </script>
  29. </head>
  30. <body>  
  31.         <div id="divMain" >
  32.             <div id="YesPrint">
  33.                  這裡是需要列印的資訊自己可以根據需要自己設計!!!
  34.             </div>
  35.             <div id="trbtn">
  36.                 <table>
  37.                     <tr>
  38.                         <td >
  39.                             <input id="btnSave" type="button" value="列印" class="button" onclick="okPrint();" />                           
  40.                         </td>
  41.                     </tr>
  42.                 </table>
  43.             </div>
  44.         </div>
  45.   
  46. </body>
  47. </html>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.