在PC上存储数据的最简单的方法 [英] The simpliest way to store data on pc

查看:191
本文介绍了在PC上存储数据的最简单的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望该网页以某种方式存储数据(即我放在网站上)。



我听说有很多方法可以在php的帮助下编辑.txt文件吗?
也许也许Chrome可以以某种方式保存该信息更容易?



赞赏任何帮助

编辑:I希望通过Chrome浏览器快速方便地访问网站,因此我不希望使用XAMPP或任何其他软件。 解决方案

最简单的方法是使用HTML5的localStorage(不需要服务器端语言),但要在页面之外获取数据并不容易(我知道您将使用已存储数据的离线页面) 。



这很简单:

  window.localStorage.setItem ('myItem','Hello World'); 

然后为了得到它,您只需要:

  window.localStorage.getItem('myItem'); 

数组方法也适用( localStorage.myItem 等)。



详细了解它这里此处



以上是一个简单的示例: http:// jsfiddle。 net / h6nz1Lq6 /

请注意,即使您删除了setter行并重新运行脚本(或者转到此链接: http://jsfiddle.net/h6nz1Lq6/1/ )。

这种方法的缺点是数据可以很容易地被清除(通过清除浏览器/网站数据,但这又类似于意外删除文件,所以如果你知道你是什么,就没有什么可怕的) '这样做),并且它在浏览器中不起作用(每个浏览器都存储它自己的localStorage)。






如果您仍然决定使用服务器端语言,关于它们的教程。对于初学者来说,使用简单的PHP脚本来编写文件可能是最简单的,但这需要在您的机器上使用服务器。


I'm creating a page for myself that could be accessed without internet connection (local storage only).

I want that page to somehow store data (that I put in the website) on my computer.

I've heard there are ways to edit .txt files with a help of php? Also maybe Chrome could somehow save that info easier?

Appreciate any help

EDIT: I want a fast and easy access to a website via Chrome only, so I prefer not to be using XAMPP or any other software.

解决方案

The easiest way would be to use HTML5's localStorage (no server-side languages needed), but it won't be easy to get that data outside of your page (I understood you'll be using that offline page which has stored data).

It's as simple as:

window.localStorage.setItem('myItem', 'Hello World');

And then to get it, you'd just do:

window.localStorage.getItem('myItem');

Array approach works as well (localStorage.myItem, etc.).

Read more about it here and here.

Here is a simple example from above: http://jsfiddle.net/h6nz1Lq6/

Notice how the text remains even after you remove the setter line and rerun the script (or just go to this link: http://jsfiddle.net/h6nz1Lq6/1/).

The downside of this approach is that the data can easily be cleared by accident (by clearing browser/website data, but again this is similar to accidental deleting of a file, so nothing to be afraid of if you know what you're doing) and that it doesn't work across browsers (each browser stores its own localStorage).


If you still decide to use a server-side language, there are millions of tutorials about them. For a beginner, it would probably be the easiest to use a simple PHP script to write a file, but that would require using a server on your machine.

这篇关于在PC上存储数据的最简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆