javascript - 使用javascript在文本文件中搜索

标签 javascript jquery

www.example.com/page_a/ 上是否可以运行 javascript 代码来搜索位于 www.example.com/page_b 的文件内的文本“hello”/my_file.txt ?

这对 javascript/jquery/任何其他 javascript 框架是否可行?

最佳答案

是的,这是可能的,而且使用 jquery 最简单。

您需要像这样“获取”文本文件的内容:

$.get("www.example.com/page_b/my_file.txt", function(contents){
   //contents variable now contains the contents of the textfile as string

   //check if file contains the word Hello
   var hasString = contents.includes("Hello");

   //outputs true if contained, else false
   console.log(hasString);
})

关于javascript - 使用javascript在文本文件中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39996539/

相关文章:

javascript - 解析云代码查询不断出现未定义

javascript - 无法评估 knockout 计算机功能

执行maps.google.Geocoder()时Javascript失败

javascript - 如何在另一个函数中调用onchange函数

javascript - 为什么 Mapbox 方向不支持 JSONP ?怎么解决呢?

jquery - 删除列表中元素后面的元素,jQuery

javascript - Gulp如何将输出保存到文件

javascript - Nodejs session 在生产环境中不持久

javascript - 单击 JS 不起作用

javascript - Webiopi 多按钮 css