简体   繁体   English

如何从文本文件读取,添加或删除Javascript中的内容?

[英]How to read from a text file, add or delete things in Javascript?

I am making a website with Javascript and I want it to have a text box, where user enters something and it reads from the text file and if it is there, it is going to output it, if it is not going to be there then I want to add it to the list, and if I want to delete something, I want to have another button which will delete the inputted word if it finds it in the list. 我正在使用Javascript创建一个网站,但我希望它有一个文本框,用户在其中输入内容,并从文本文件中读取内容,如果存在,则将其输出,如果不存在,则将其输出我想将其添加到列表中,如果要删除某些内容,我想拥有另一个按钮,该按钮将在列表中找到输入的单词时将其删除。

I can do the HTML part fine, but I have 0 experience with Javascript and can anyone tell me what functions I should use and how its going to be connected with HTML. 我可以很好地完成HTML的工作,但是我对Javascript的使用经验为零,谁能告诉我应该使用哪些功能以及如何将其与HTML连接。

I know that form in HTML, which I will need should have action which is going to be connection from javascript to HTML, but other then that part I do now know how to do it in Javascript. 我知道HTML格式的表单,我需要做的就是从javascript到HTML的连接,但是除了那部分,我现在知道如何在Javascript中实现。

Any help would be appreciated! 任何帮助,将不胜感激! Thanks! 谢谢!

Reading a file with Node 用Node读取文件

var fs = require('fs');
fs.readFile('file.txt', function(err,data) {
  if ( err ) throw err;
  console.log("Contents of file.txt: %s",data);
});

Saving a file with Node 用Node保存文件

var fs = require('fs');
fs.writeFile("output.txt", "Hello World!", function(err) {
    if ( err ) return console.log(err);
    console.log("The file was saved!");
}); 

Further reading: Node Filesystem API 进一步阅读: Node Filesystem API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM