我的问题时怎样才能把textbox的内容作为打印出来,而不是打印html流?

解决方案 »

  1.   

    发错了:
    我的问题是怎样才能把textbox的内容作为打印出来,而不是打印html流?
    谢谢,请指点
    源码如下:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1"><title>
    无标题页
    </title>
      <link href="Style/style.css"rel="stylesheet" type="text/css">
    <script language="javascript" type="text/javascript">
    String.prototype.ReplaceAll = stringReplaceAll;
    function  stringReplaceAll(AFindText,ARepText){
      raRegExp = new RegExp(AFindText,"g");
      return this.replace(raRegExp,ARepText)
    }
    function Button1_onclick() {
         
         var tb=document.getElementById("TextBox1");
         tb.style.display="none";
         t=tb.innerHTML;
         t=t.ReplaceAll("&lt;","<");
         t=t.ReplaceAll("&gt;",">");
         //t=t.ReplaceAll("&nbsp;","ok");
         btn.style.display="none";
         longStr=t;
          cli.innerHTML=t;
          arr=longStr.split("@@@@@2008");
          for(i=1;i<arr.length;i++)
          {
             cli.innerHTML="";         
             cli.innerText=arr[i];
             //alert(arr[i]);          document.all.WebBrowser.ExecWB(6,6);           
          }
          cli.innerHTML="";     
          btn.style.display="";
          ser.style.display="";
    }
    </script>
    </head>
    <body>    <form name="form1" method="post" action="fullPrint.aspx" id="form1">
    <div>
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQ5NDU0NDYwM2RkfyRpnIzWaVcWdG/2y13vgDPm2NM=" />
    </div><script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
         <OBJECT id=WebBrowser   classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2   height=0   width=0>      
       </OBJECT> 
        <div id="btn">
            <table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
        <tr>
        <td height="25" class="ListTopBorder" background="Images/button/2k3ButtonBar.gif"> 
                
                <a onclick="window.close();" id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')"> <IMG src="Images/button/close.gif" border="0" align="absMiddle"/>
    关 闭
    </a>
                <input id="Button1" type="button" value="打印" language="javascript" onclick="return Button1_onclick()" /></td>      
        </tr>
        <tr> <td style="height: 538px">
            <textarea name="TextBox1" rows="2" cols="20" id="TextBox1" style="height:289px;width:205px;">@@@@@2008&lt;html xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot;
    xmlns:w=&quot;urn:schemas-microsoft-com:office:word&quot;
    xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;&lt;head&gt;
    &lt;meta http-equiv=Content-Type content=&quot;text/html; charset=gb2312&quot;&gt;
    &lt;meta name=ProgId content=Word.Document&gt;
    &lt;meta name=Generator content=&quot;Microsoft Word 11&quot;&gt;
    &lt;meta name=Originator content=&quot;Microsoft Word 11&quot;&gt;
    &lt;link rel=File-List href=&quot;fengMian.files/filelist.xml&quot;&gt;
    &lt;title&gt;中  华  人  民  共  和  国&lt;/title&gt;
    &lt;!--[if gte mso 9]&gt;&lt;xml&gt;
     &lt;o:DocumentProperties&gt;
      &lt;o:Author&gt;[lls]&lt;/o:Author&gt;
      &lt;o:LastAuthor&gt;[lls]&lt;/o:LastAuthor&gt;
    &lt;p class=MsoNormal style='text-indent:388.5pt;mso-char-indent-count:17.59'&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span style='font-size:22.0pt;font-family:
    宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;'&gt;宗&lt;/span&gt;&lt;/b&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span style='font-size:22.0pt'&gt; &lt;/span&gt;&lt;/b&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span style='font-size:22.0pt;font-family:
    宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;'&gt;地&lt;/span&gt;&lt;/b&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span style='font-size:22.0pt'&gt; &lt;/span&gt;&lt;/b&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span style='font-size:22.0pt;font-family:
    宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;'&gt;号:&lt;/span&gt;&lt;/b&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span lang=EN-US style='font-size:22.0pt'&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=MsoNormal style='text-indent:389.4pt;mso-char-indent-count:17.63'&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span style='font-size:22.0pt;font-family:
    宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;'&gt;项目名称:&lt;/span&gt;&lt;/b&gt;&lt;b
    style='mso-bidi-font-weight:normal'&gt;&lt;span lang=EN-US style='font-size:22.0pt'&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
    </textarea></td></tr>
    </table>   
        </div>
            <div id="ser"></div>
             <div id="cli"></div>
        
    <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKY8frcAQKxi96RBQLM9PumDwLs0bLrBlzKiYymOn/uDfOkuMpkYbxRkA2f" />
    </div></form>
    </body>
    </html>
      

  2.   

    两种办法
    1、定义一个style如
    <style media=print>   
    .button {
    …略
    DISPLAY: NONE
    }
    </style>
    这样具有这个button样式的元素在打印时不显示
    2、用一个专用页面,事先定义好所有与打印相关的样式,当其它页面需要打印时,将需要打印的HTML传给专用打印页面去执行打印。
    我常用第2种。
      

  3.   

    你textbox的内容本身就带着html流?
      

  4.   

    var div=document.createElement("div");
    div.innerHTML=t;
    t=div.innerText;
      

  5.   

    我的textbox里面的html流是从后台传过来的,我想把这个html流显示的格式内容打印出来,不想打印html流,怎么办,请高手指点?
      

  6.   

    function Button1_onclick() { 
          
         var tb=document.getElementById("TextBox1"); 
         tb.style.display="none"; 
         t=tb.innerHTML; 
         t=t.ReplaceAll("&lt;"," <"); 
         t=t.ReplaceAll("&gt;",">");
         var div=document.createElement("div"); 
         div.innerHTML=t; 
         t=div.innerText;
         //t=t.ReplaceAll("&nbsp;","ok"); 
         btn.style.display="none"; 
         longStr=t; 
          cli.innerHTML=t; 
          arr=longStr.split("@@@@@2008"); 
          for(i=1;i <arr.length;i++) 
          { 
             cli.innerHTML="";          
             cli.innerText=arr[i]; 
             //alert(arr[i]);           document.all.WebBrowser.ExecWB(6,6);            
          } 
          cli.innerHTML="";      
          btn.style.display=""; 
          ser.style.display=""; 

      

  7.   

    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1"> <title> 
    无标题页 
    </title> 
       <link href="Style/style.css"rel="stylesheet" type="text/css"> 
    <script language="javascript" type="text/javascript"> 
    String.prototype.ReplaceAll = stringReplaceAll; 
    function  stringReplaceAll(AFindText,ARepText){ 
      raRegExp = new RegExp(AFindText,"g"); 
      return this.replace(raRegExp,ARepText) 

    function Button1_onclick() { 
          
         var tb=document.getElementById("TextBox1"); 
         tb.style.display="none"; 
         t=tb.innerHTML; 
         t=t.ReplaceAll("&lt;"," <"); 
         t=t.ReplaceAll("&gt;",">"); 
         //t=t.ReplaceAll("&nbsp;","ok"); 
         btn.style.display="none"; 
         longStr=t; 
          //cli.innerHTML=t; 
          arr=longStr.split("@@@@@2008");
    var div=document.createElement("div"); 
          for(i=1;i <arr.length;i++) 
          { 
             cli.innerHTML="";          
            cli.innerHTML=arr[i]; 
    //cli.innerText=arr[i];         // alert(arr[i]); 
    //div.innerHTML=arr[i]; 
              document.all.WebBrowser.ExecWB(6,6);            
          } 
          cli.innerHTML="";      
          btn.style.display=""; 
          ser.style.display=""; 

    </script> 
    </head> 
    <body>      <form name="form1" method="post" action="fullPrint.aspx" id="form1"> 
    <div> 
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> 
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> 
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQ5NDU0NDYwM2RkfyRpnIzWaVcWdG/2y13vgDPm2NM=" /> 
    </div> <script type="text/javascript"> 
    // <![CDATA[ 
    var theForm = document.forms['form1']; 
    if (!theForm) { 
        theForm = document.form1; 

    function __doPostBack(eventTarget, eventArgument) { 
        if (!theForm.onsubmit  | | (theForm.onsubmit() != false)) { 
            theForm.__EVENTTARGET.value = eventTarget; 
            theForm.__EVENTARGUMENT.value = eventArgument; 
            theForm.submit(); 
        } 

    //]]> 
    </script> 
          <OBJECT id=WebBrowser   classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2   height=0   width=0>       
        </OBJECT>  
         <div id="btn"> 
             <table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0"> 
         <tr> 
         <td height="25" class="ListTopBorder" background="Images/button/2k3ButtonBar.gif">  
                 
                 <a onclick="window.close();" id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')">  <IMG src="Images/button/close.gif" border="0" align="absMiddle"/> 
    关 闭 
    </a> 
                 <input id="Button1" type="button" value="打印" language="javascript" onclick="return Button1_onclick()" /> </td>       
         </tr> 
         <tr>  <td style="height: 538px"> 
             <textarea name="TextBox1" rows="2" cols="20" id="TextBox1" style="height:289px;width:205px;">@@@@@2008&lt;html xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot; 
    xmlns:w=&quot;urn:schemas-microsoft-com:office:word&quot; 
    xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt; &lt;head&gt; 
    &lt;/head&gt;
    中  华  人  民  共  和  国中  华  人  民  共  和  国
    &lt;/body&gt; &lt;/html&gt; 
    </textarea> </td> </tr> 
    </table>    
         </div> 
             <div id="ser"> </div> 
              <div id="cli"> </div> 
         
    <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKY8frcAQKxi96RBQLM9PumDwLs0bLrBlzKiYymOn/uDfOkuMpkYbxRkA2f" /> 
    </div> </form> 
    </body> 
    </html> 
      

  8.   

    function Button1_onclick() {  
           
         var tb=document.getElementById("TextBox1");  
         tb.style.display="none";  
         t=tb.innerHTML;  
         t=t.ReplaceAll("&lt;","  <");  
         t=t.ReplaceAll("&gt;",">"); 
         var div=document.createElement("div");  
         div.innerHTML=t;  
         t=div.innerText; 
         //t=t.ReplaceAll("&nbsp;","ok");  
         btn.style.display="none";  
         longStr=t;  
          cli.innerHTML=t;  
          arr=longStr.split("@@@@@2008");  
          for(i=1;i  <arr.length;i++)  
          {  
             cli.innerHTML="";           
             cli.innerText=arr[i];  
             //alert(arr[i]);            document.all.WebBrowser.ExecWB(6,6);             
          }  
          cli.innerHTML="";       
          btn.style.display="";  
          ser.style.display="";  
    }