Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否有一种方法可以将文本文档写入屏幕,并在文档中搜索特定单词并打印出来_Javascript_Html_Jquery - Fatal编程技术网

Javascript 是否有一种方法可以将文本文档写入屏幕,并在文档中搜索特定单词并打印出来

Javascript 是否有一种方法可以将文本文档写入屏幕,并在文档中搜索特定单词并打印出来,javascript,html,jquery,Javascript,Html,Jquery,document.getElementById('inputfile').addEventListener('change',function(){ var fr=new FileReader(); fr.onload=函数(){ document.getElementById('output').textContent=fr.result; } fr.readAsText(this.files[0]); }) fr.result是一个字符串。您可以使用string.split(“”)将此字

document.getElementById('inputfile').addEventListener('change',function(){
var fr=new FileReader();
fr.onload=函数(){
document.getElementById('output').textContent=fr.result;
}
fr.readAsText(this.files[0]);
})



fr.result是一个字符串。您可以使用
string.split(“”)
将此字符串拆分为一个单词数组。并使用
array.some(checkingFunction)
检查这些单词是否与您的预定义单词匹配,这些单词也应该在数组中。 这是你们代码的延续

let myWords = ['hello', 'world', 'what', 'is', 'happening'];
function checkIfWordExistInmyWords(word){
   return myWords.includes(word);
 }
let docWords = fr.result.split(' ');
console.log(docWords.some(checkIfWordExistInmyWords))

您想从文本文档中提取特定的单词并打印到屏幕上吗?@julius yeah,或者有一个单词列表,程序会检查它是否包含这些单词,并对包含这些特定单词的单词说是或否。我收到的错误表明fr未定义