javascript打印问题 我的问题时怎样才能把textbox的内容作为打印出来,而不是打印html流? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 发错了:我的问题是怎样才能把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("<","<"); t=t.ReplaceAll(">",">"); //t=t.ReplaceAll(" ","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<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:w="urn:schemas-microsoft-com:office:word"xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=gb2312"><meta name=ProgId content=Word.Document><meta name=Generator content="Microsoft Word 11"><meta name=Originator content="Microsoft Word 11"><link rel=File-List href="fengMian.files/filelist.xml"><title>中 华 人 民 共 和 国</title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>[lls]</o:Author> <o:LastAuthor>[lls]</o:LastAuthor><p class=MsoNormal style='text-indent:388.5pt;mso-char-indent-count:17.59'><bstyle='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>宗</span></b><bstyle='mso-bidi-font-weight:normal'><span style='font-size:22.0pt'> </span></b><bstyle='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>地</span></b><bstyle='mso-bidi-font-weight:normal'><span style='font-size:22.0pt'> </span></b><bstyle='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>号:</span></b><bstyle='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:22.0pt'><o:p></o:p></span></b></p><p class=MsoNormal style='text-indent:389.4pt;mso-char-indent-count:17.63'><bstyle='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>项目名称:</span></b><bstyle='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:22.0pt'><o:p></o:p></span></b></p></div></body></html></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> 两种办法1、定义一个style如<style media=print> .button {…略DISPLAY: NONE}</style>这样具有这个button样式的元素在打印时不显示2、用一个专用页面,事先定义好所有与打印相关的样式,当其它页面需要打印时,将需要打印的HTML传给专用打印页面去执行打印。我常用第2种。 你textbox的内容本身就带着html流? var div=document.createElement("div");div.innerHTML=t;t=div.innerText; 我的textbox里面的html流是从后台传过来的,我想把这个html流显示的格式内容打印出来,不想打印html流,怎么办,请高手指点? function Button1_onclick() { var tb=document.getElementById("TextBox1"); tb.style.display="none"; t=tb.innerHTML; t=t.ReplaceAll("<"," <"); t=t.ReplaceAll(">",">"); var div=document.createElement("div"); div.innerHTML=t; t=div.innerText; //t=t.ReplaceAll(" ","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=""; } <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("<"," <"); t=t.ReplaceAll(">",">"); //t=t.ReplaceAll(" ","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<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> </head>中 华 人 民 共 和 国中 华 人 民 共 和 国</body> </html> </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> function Button1_onclick() { var tb=document.getElementById("TextBox1"); tb.style.display="none"; t=tb.innerHTML; t=t.ReplaceAll("<"," <"); t=t.ReplaceAll(">",">"); var div=document.createElement("div"); div.innerHTML=t; t=div.innerText; //t=t.ReplaceAll(" ","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=""; } 表单验证问题 js缓存问题 javascript 做jmail自动发送邮件的问题 求助一个关于网页查询页面的简单问题,请求帮忙! JS问题 求老大们帮忙! 这个联动问题怎么解决啊,大侠们救救我啊 community.csdn.net页面里为什么有这样一行代码 大家帮帮忙好么 如何实现滚动栏中信息的最后一个字符消失后,原信息就从头开始滚动出现? 这个无限弹出菜单为什么在mozilla里乱闪,前次改的w3c的菜单,改成多浏览器版,结果出现了这个问题。 超级小菜提问:Javascript 小问题 请教一个静态页面里插入JavaScript脚本能否调用OCX控件里的方法
我的问题是怎样才能把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("<","<");
t=t.ReplaceAll(">",">");
//t=t.ReplaceAll(" ","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<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="fengMian.files/filelist.xml">
<title>中 华 人 民 共 和 国</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>[lls]</o:Author>
<o:LastAuthor>[lls]</o:LastAuthor>
<p class=MsoNormal style='text-indent:388.5pt;mso-char-indent-count:17.59'><b
style='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:
宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>宗</span></b><b
style='mso-bidi-font-weight:normal'><span style='font-size:22.0pt'> </span></b><b
style='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:
宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>地</span></b><b
style='mso-bidi-font-weight:normal'><span style='font-size:22.0pt'> </span></b><b
style='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:
宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>号:</span></b><b
style='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:22.0pt'><o:p></o:p></span></b></p><p class=MsoNormal style='text-indent:389.4pt;mso-char-indent-count:17.63'><b
style='mso-bidi-font-weight:normal'><span style='font-size:22.0pt;font-family:
宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>项目名称:</span></b><b
style='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:22.0pt'><o:p></o:p></span></b></p></div></body></html>
</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>
1、定义一个style如
<style media=print>
.button {
…略
DISPLAY: NONE
}
</style>
这样具有这个button样式的元素在打印时不显示
2、用一个专用页面,事先定义好所有与打印相关的样式,当其它页面需要打印时,将需要打印的HTML传给专用打印页面去执行打印。
我常用第2种。
div.innerHTML=t;
t=div.innerText;
var tb=document.getElementById("TextBox1");
tb.style.display="none";
t=tb.innerHTML;
t=t.ReplaceAll("<"," <");
t=t.ReplaceAll(">",">");
var div=document.createElement("div");
div.innerHTML=t;
t=div.innerText;
//t=t.ReplaceAll(" ","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="";
}
<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("<"," <");
t=t.ReplaceAll(">",">");
//t=t.ReplaceAll(" ","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<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40"> <head>
</head>
中 华 人 民 共 和 国中 华 人 民 共 和 国
</body> </html>
</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>
var tb=document.getElementById("TextBox1");
tb.style.display="none";
t=tb.innerHTML;
t=t.ReplaceAll("<"," <");
t=t.ReplaceAll(">",">");
var div=document.createElement("div");
div.innerHTML=t;
t=div.innerText; //t=t.ReplaceAll(" ","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="";
}