如何在根目录中获取外部文本文件并使用javascript将其附加到p元素?
我正在做一个项目,需要检索.txt文件中的数据并将其数据附加到p元素 这是我的HTML:如何在根目录中获取外部文本文件并使用javascript将其附加到p元素?,javascript,filereader,Javascript,Filereader,我正在做一个项目,需要检索.txt文件中的数据并将其数据附加到p元素 这是我的HTML: <p id="displayName"></p> 上面的行抛出一个错误。我该如何着手解决这个问题 非常感谢您的帮助! 谢谢大家! 根据,在FileReader中没有onload属性,只有一个onload属性。它有一个loadend事件,但不能作为属性使用,因此需要使用addEventListener reader.addEventListener("loadend", fu
<p id="displayName"></p>
上面的行抛出一个错误。我该如何着手解决这个问题
非常感谢您的帮助!
谢谢大家! 根据,在FileReader
中没有onload
属性,只有一个onload
属性。它有一个loadend
事件,但不能作为属性使用,因此需要使用addEventListener
reader.addEventListener("loadend", function(e) {
var txtArea = document.createElement('textarea');
txtArea.value = this.result;
document.getElementById("displayName").appendChild(txtArea);
};
它会抛出什么错误?
reader.addEventListener("loadend", function(e) {
var txtArea = document.createElement('textarea');
txtArea.value = this.result;
document.getElementById("displayName").appendChild(txtArea);
};