【发布时间】:2019-04-22 04:10:07
【问题描述】:
我正在尝试使用 javascript 来读取 .txt 文件,但我似乎无法在线找到任何方法。该代码的目的是扫描文本文件中的某个字符串。在我的代码中,用户故意上传文件并将其存储在一个变量中,但我找不到一种方法来实际读取文件中的文本并将其转换为字符串。任何帮助将不胜感激,谢谢。
document.getElementById("answer").addEventListener(search);
document.getElementById("actualAns").addEventListener(search);
function myFunction() {
var targetAns = document.getElementById("answer").value; //the user inputs a .txt file
var actualAns = document.getElementById("actualAns").value; //the user enters the string they want to search
var n = actualAns.search(targetAns); // this part does not work, it should search the text file but it only searches the name
if(n > -1) {
document.getElementById("result").innerHTML = "Correct";
} else {
document.getElementById("result").innerHTML = "Incorrect";
}
}
【问题讨论】:
标签: javascript jquery html text