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>

解决方案 »

  1.   

    fason(阿信) 老大,不知道是什么有错误,请指教!是不是这样啊?<html><head>
    <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>
      

  2.   

    我想要这样的效果:<body><table>
    <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>
      

  3.   

    fason(阿信),你的方法不错,只是不明白这句是什么意思:
    <IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
    望指点,谢谢~!Cbfan(民族英雄~~) ,你是否在"新建网页1"的相同路径下存在文件“text.txt”?
      

  4.   

    fason(阿信),能有更好的方法保留TXT文件的段落格式吗?
    我对字符的编码不是很清楚,请指点,谢谢~!
      

  5.   

    to:chouchy(alex chou) 对,可以解决么?
      

  6.   

    try:
    <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,"&#38;");
    str=str.replace(/\x3c/g,"&#60;");
    str=str.replace(/\x3e/g,"&#62;");
    str=str.replace(/\x22/g,"&#34;");
    str=str.replace(/\x27/g,"&#39;");
    str=str.replace(/\x20/g,"&#160;");
    str=str.replace(/\x0d\x0a/g,"<br/>");
    return str;
    }function onDownloadDone(downDate){
    showImport.innerHTML=downDate.EncodeHTML()
    }
    oDownload.startDownload('test.txt',onDownloadDone)
    </script>
    </body>
      

  7.   

    想了一下
    应该可以的
    下边的是个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>
      

  8.   

    <html>
    <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/,"&nbsp;");
    }
    oDownload.startDownload('text.txt',onDownloadDone)
    </script>
    </body>
    </html>
    以上代码可以实现了。
      

  9.   

    感谢fason(阿信) 和 hillhero789(丘) !但是2位的代码都只是把test.txt的内容显示在网页中,我想要把test.txt里面的所有中文字符后面加一个半角的空格再显示出来啊。
      

  10.   

    sorry:忘了
    改一下
    String.prototype.EncodeHTML=function()
    {
    var str=this;
    str=str.replace(/(.)/g,'$1 ')
    str=str.replace(/\x26/g,"&#38;");
    str=str.replace(/\x3c/g,"&#60;");
    str=str.replace(/\x3e/g,"&#62;");
    str=str.replace(/\x22/g,"&#34;");
    str=str.replace(/\x27/g,"&#39;");
    str=str.replace(/\x20/g,"&#160;");
    str=str.replace(/\x0d/g,"<br>");
    return str;
    }
      

  11.   

    <span id=showImport></span>
    <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,"&#38;");
    str=str.replace(/\x3c/g,"&#60;");
    str=str.replace(/\x3e/g,"&#62;");
    str=str.replace(/\x22/g,"&#34;");
    str=str.replace(/\x27/g,"&#39;");
    str=str.replace(/\x20/g,"&#160;");
    str=str.replace(/\x0d/g,"<br>");
    return str;
    }function onDownloadDone(downDate){
    showImport.innerHTML=downDate.EncodeHTML()
    }
    oDownload.startDownload('test.txt',onDownloadDone)
    </script>我想多问一句,如果我想把上面的代码加到<table>之间,就是想把txt的文字显示在网页里的一个表格里,以控制整体页面。不过上面的代码我试过,不可以。谢谢!24小时给分。
      

  12.   

    可以把span改为table就行了
    <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,"&#38;");
    str=str.replace(/\x3c/g,"&#60;");
    str=str.replace(/\x3e/g,"&#62;");
    str=str.replace(/\x22/g,"&#34;");
    str=str.replace(/\x27/g,"&#39;");
    str=str.replace(/\x20/g,"&#160;");
    str=str.replace(/\x0d/g,"<br>");
    return str;
    }function onDownloadDone(downDate){
    showImport.innerHTML=downDate.EncodeHTML()
    }
    oDownload.startDownload('test.txt',onDownloadDone)
    </script>