简体   繁体   English

如何将HTML用户输入保存为txt。 文件并将保存的输入加载到HTML文件中?

[英]How to Save HTML userinput into a txt. file and Load the saved input into the HTML file?

I've recently made a CharacterSheet for a game using HTML. 我最近为使用HTML的游戏制作了CharacterSheet。 The HTML file mainly consists out of the <input type="text"> , <input type="number"> , <input type="checkbox"> , <input type="radio"> , <select> , or <textarea> tags to insert data. HTML文件主要由<input type="text"><input type="number"><input type="checkbox"><input type="radio"><select><textarea>标记以插入数据。 Is there a way to save all the inserted data into a txt. 有没有一种方法可以将所有插入的数据保存到txt中。 file and load it up into the HTML document upon startup of the HTML document? 文件,并在HTML文档启动时将其加载到HTML文档中?

In some other posts they had the problem that browsers didn't allow writing to a file as they saw it as a security issue. 在其他一些帖子中,他们遇到的问题是浏览器不允许将文件写入,因为他们将其视为安全问题。 But as both the HTML and txt files are on my pc there shouldn't be a problem, i think. 但是,我认为HTML和txt文件都在我的电脑上,应该没有问题。

you could allow the user to download a text file, then when they start the game upload it where you can parse it, but a better way is to just use the localStorage built into modern browsers. 您可以允许用户下载文本文件,然后在他们开始游戏时将其上传到可以解析的位置,但是更好的方法是仅使用现代浏览器中内置的localStorage It will be stored permanently in the users browser until it's deleted. 它将被永久存储在用户浏览器中,直到被删除。

localStorage.game = JSON.stringify({ score: 1 }) // put
console.log(JSON.parse(localStorage.game)) // get

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

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