javascript如何读取txt文本内容?

我想在点击 某个按钮后 在 这个文本框里显示txt文件的内容
如何显示啊??

<!DOCTYPE html>
<html>
  <head>
    <title>文件示例</title>
    <meta name="name" content="content" charset="utf-8">
  </head>
  <body>
      <input type="file" id="file" />
      <input type="button" onclick="readText()" value="File Button">
      <div id="tt">
 
      </div>
  </body>
</html>
<script charset="utf-8">
window.onload=function () {
  if(typeof(FileReader)=="undefined")
  {
    alert("你的浏览器不支持文件读取");
    document.write("");
  }else
  {
    alert("你的浏览器支持文件读取");
  }
}
  function readText() {
      var file=document.getElementById("file").files[0];
      var reader=new FileReader();
      reader.readAsText(file);
      reader.onload=function(data)
      {
        var tt=document.getElementById("tt")
        tt.innerHTML=this.result;
      }
    }
 
</script>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-02-22
txt在客服端还是服务器?
相似回答