【问题标题】:Make an online application to open txt file [closed]制作在线应用程序以打开 txt 文件 [关闭]
【发布时间】:2015-08-06 07:51:44
【问题描述】:

这有点牵强,但我知道它可以而且已经做到了。你知道如何制作一个在线网站/应用程序来打开文件吗?基本上是一个可以读取和输出 HTML/TXT 文件的网站或应用程序。我最好使用 javascript 或 jquery,但任何适用于网站的语言也可以。有像Text for Chrome 这样的在线应用程序可以做到这一点。你知不知道怎么?如果你能在这里帮助我,那就太好了。如果您有任何问题,请随时提出。

【问题讨论】:

  • 可以描述“打开文件”吗?读取用户上传的文件?
  • 是的,就像那样。例如,用户将文件上传到网站,网站/应用程序读取文件并将文件放回到屏幕上。
  • 见帖子。利用 inputtextarea 元素; onchange事件; FileReader

标签: javascript jquery html file readable


【解决方案1】:

尝试使用<input> 元素; <textarea> 元素; accept="text/plain" 属性位于 input 元素; onchange 事件附加到 input 元素; FileReader()onchange 事件中将上传的文本文件输出到<textarea> 元素

var input = document.getElementById("input");
var output = document.querySelector("[for=input]");
input.onchange = function(e) {
  var reader = new FileReader();
  reader.onload = function(evt) {
    output.textContent = evt.target.result;
  };
  reader.readAsText(e.target.files[0]);
};
<input id="input" type="file" accept="text/plain" /><br />
<textarea for="input" style="width:300px;height:300px;"></textarea>

【讨论】:

    猜你喜欢
    • 2011-04-26
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多