2013-03-12 68 views
0

我在正確打印DIV content.it打印出它像undefined..can任何一個「SYS」的錯誤告訴我解決的問題,Sys系統的打印功能未定義

<div id="mydiv" runat="server" style="display:none;"> 

     </div> 

和我的JavaScript :

function Print() { 


      var PrintDiv = $('#' + '<%= mydiv.ClientID %>').html(); 

      //var NewWindow = window.open('', '', 'width=500,height=500'); 
      var NewWindow = window.open('', '_blank', 'location=1,status=1,scrollbars=1,width=1000,height=700'); 
      NewWindow.document.open("text/html"); 
      NewWindow.document.write('<html><head><title></title>'); 
      NewWindow.document.write('<link href="CSS/style.css" rel="stylesheet" type="text/css" />'); 

      NewWindow.document.write('</head><body onload="window.print()">'); 
      NewWindow.document.write(PrintDiv); 
      NewWindow.document.write('</body></html>'); 

      NewWindow.document.close(); 


     } 

回答

0

喜打印DIV我做下面的東西,希望你會找到解決辦法

功能printdiv(strid,rptName){

 var prtContent = document.getElementById(strid); 
     // Intial header 
     var html = '<html>\n<head>\n'; 
     html += '<title>' + 'Name of your project : ' + rptName + '</title>'; 
     // Get value for header for Telerik stylesheet 
     if (document.getElementsByTagName != null) { 
      var headTags = document.getElementsByTagName("head"); 
      if (headTags.length > 0) 
       html += headTags[0].innerHTML; 
     } 
     html += ' <title>' + 'Name of your project-' + rptName + ' </title>'; 
     // End the header and open body 
     html += '\n</head>\n<body>\n'; 

     if (prtContent != null) { // Get all html 
      html += document.getElementById(strid).innerHTML; 
     } 
     else { 
      alert("Could not find the print div"); 
      return; 
     } 
     //End the body and html 
     html += "\n</body></html>"; 

     // Opem new wind 
     var WinPrint = window.open('', '', 'letf=10,top=10,width="450",height="250",toolbar=1,scrollbars=1,status=0'); 

     WinPrint.document.write(html); 
     WinPrint.document.close(); 
     WinPrint.focus(); 
     WinPrint.print(); 
     return false; 
    } 
+0

是,,但它顯示錯誤消息Sys系統未定義 – 2013-03-12 06:24:19

+0

可以調試,讓我知道這行的投擲的錯誤。 – 2013-03-12 06:29:26

+0

我得到錯誤var PrintDiv = $('#'+'ctl00_ContentPlaceHolder1_mydiv')。innerHtml(); – 2013-03-12 06:33:41

0

我認爲只有一個語句會改變你的代碼,

var PrintDiv = $('#' + '<%= mydiv.ClientID %>').innerHtml(); 

如果要調用HTML作爲div樣式>>顯示沒有被調用,

檢查與代碼

alert(PrintDiv); 

如果這是返回值,那麼它將打印。

我希望這將有助於:)

+0

它工作在Firefox但不工作的IE8,你能告訴我解決方案 – 2013-03-12 07:21:18