try:
<span id=showImport></span>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>
function onDownloadDone(downDate){
showImport.innerHTML=downDate.split("").join(" ")
}
oDownload.startDownload('text.txt',onDownloadDone)
</script>
<span id=showImport></span>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>
function onDownloadDone(downDate){
showImport.innerHTML=downDate.split("").join(" ")
}
oDownload.startDownload('text.txt',onDownloadDone)
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head><body><span id=showImport></span>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>
function onDownloadDone(downDate){
showImport.innerHTML=downDate.split("").join(" ")
}
oDownload.startDownload('text.txt',onDownloadDone)
</script></body></html>
<p><a href="1.txt">把1.txt中的字符前面加个空格,然后生成1.htm,打开。</a></p>
<p><a href="2.txt">把2.txt中的字符前面加个空格,然后生成2.htm,打开。</a></p>
<p><a href="3.txt">把3.txt中的字符前面加个空格,然后生成3.htm,打开。</a></p>
</table></body>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
望指点,谢谢~!Cbfan(民族英雄~~) ,你是否在"新建网页1"的相同路径下存在文件“text.txt”?
我对字符的编码不是很清楚,请指点,谢谢~!
<body>
<span id=showImport></span>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>
String.prototype.EncodeHTML=function()
{
var str=this;
str=str.replace(/\x26/g,"&");
str=str.replace(/\x3c/g,"<");
str=str.replace(/\x3e/g,">");
str=str.replace(/\x22/g,""");
str=str.replace(/\x27/g,"'");
str=str.replace(/\x20/g," ");
str=str.replace(/\x0d\x0a/g,"<br/>");
return str;
}function onDownloadDone(downDate){
showImport.innerHTML=downDate.EncodeHTML()
}
oDownload.startDownload('test.txt',onDownloadDone)
</script>
</body>
应该可以的
下边的是个demo:
<script>
function d()
{
document.all.i.innerText=document.all.s.value.replace(/\u000d\u000a/,"\n").replace(/\u0020/," ");
}
</script>
<body onLoad="d()">
<textarea id="s"> a a
aa</textarea>
<br>
<span id="i"></span>
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
</head>
<body>
<span id=showImport></span>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>
function onDownloadDone(downDate){
showImport.innerHTML=downDate.replace(/\u000d\u000a/,"<br>").replace(/\u0020/," ");
}
oDownload.startDownload('text.txt',onDownloadDone)
</script>
</body>
</html>
以上代码可以实现了。
改一下
String.prototype.EncodeHTML=function()
{
var str=this;
str=str.replace(/(.)/g,'$1 ')
str=str.replace(/\x26/g,"&");
str=str.replace(/\x3c/g,"<");
str=str.replace(/\x3e/g,">");
str=str.replace(/\x22/g,""");
str=str.replace(/\x27/g,"'");
str=str.replace(/\x20/g," ");
str=str.replace(/\x0d/g,"<br>");
return str;
}
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>String.prototype.EncodeHTML=function()
{
var str=this;
str=str.replace(/(.)/g,'$1 ')
str=str.replace(/\x26/g,"&");
str=str.replace(/\x3c/g,"<");
str=str.replace(/\x3e/g,">");
str=str.replace(/\x22/g,""");
str=str.replace(/\x27/g,"'");
str=str.replace(/\x20/g," ");
str=str.replace(/\x0d/g,"<br>");
return str;
}function onDownloadDone(downDate){
showImport.innerHTML=downDate.EncodeHTML()
}
oDownload.startDownload('test.txt',onDownloadDone)
</script>我想多问一句,如果我想把上面的代码加到<table>之间,就是想把txt的文字显示在网页里的一个表格里,以控制整体页面。不过上面的代码我试过,不可以。谢谢!24小时给分。
<table>
<tr>
<td id=showImport></td>
</tr>
</table>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>String.prototype.EncodeHTML=function()
{
var str=this;
str=str.replace(/(.)/g,'$1 ')
str=str.replace(/\x26/g,"&");
str=str.replace(/\x3c/g,"<");
str=str.replace(/\x3e/g,">");
str=str.replace(/\x22/g,""");
str=str.replace(/\x27/g,"'");
str=str.replace(/\x20/g," ");
str=str.replace(/\x0d/g,"<br>");
return str;
}function onDownloadDone(downDate){
showImport.innerHTML=downDate.EncodeHTML()
}
oDownload.startDownload('test.txt',onDownloadDone)
</script>