[英]How to read(in), print(out) value to text file by Javascript?
I'm working on with my simple server. 我正在使用我的简单服务器。 And i need a little data(number) to be used for my project, but i don't want to use database(cuz i don't like SQL).
而且我需要一些数据(数字)用于我的项目,但是我不想使用数据库(因为我不喜欢SQL)。 So is there any way that i could save my data in file text and use data in that file text?
那么,有什么方法可以将数据保存在文件文本中并在该文件文本中使用数据?
I want to use Js to print number from roll call program.htm to hr.txt and then i want read number from hr.txt to roll call program.htm which make a perfect data storage.I tested this kind of saving data in my c++ IDE and it worked, but i don't know if it can work on a server. 我想用Js将数字从点名呼叫program.htm打印到hr.txt,然后我想从hr.txt中读取号名进行滚动呼叫program.htm,从而实现了完美的数据存储。 C + +的IDE,它的工作原理,但我不知道它是否可以在服务器上工作。 So can you guys help me out?
你们可以帮我吗?
Here is a sample code for saving the data as a text file and loading in the HTML. 这是用于将数据保存为文本文件并加载到HTML中的示例代码。 You can modify this code and use as per your convenience.
您可以根据需要方便地修改此代码并使用。
function saveTextAsFile()
{
var textToSave = document.getElementById("inputTextToSave").value;
var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
function loadFileAsText()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.getElementById("inputTextToSave").value = textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.