2017-02-17 33 views
0

试图为学校创建笔记应用程序,但我对某些事情感到困惑。我如何做到这一点,以便当我输入一个表单块时,即使在刷新页面后,它也会保存我放入文本块内的所有内容。注意使用本地存储器拍摄应用程序

我对本地存储如何工作有点困惑。一段javascript代码的简单答案会很好。

回答

0

localStorage API非常简单易用,您可以在其MDN页面上找到API基本使用信息:localStorage API和网页存储页面:Web Storage

我还提供了一个JSFiddle示例,了解与您的应用程序类似的应用程序如何使用API​​功能,该功能可以在here找到。

有多种方式使用API​​ 示例设置和获取值:

// Using the getItem & setItem funcitons 
localStorage.setItem('key', 'value'); // sets 'key' to 'value' 
localStorage.getItem('key'); // returns: 'value' 

// Simple member assignment 
localStorage.note = 'value'; // 'note' => 'value' 
localStorage.note; // 'value' 
localStorage['note2'] = 'some other value'; // 'note2' => 'some other value' 
localStorage['note2']; // 'some other value' 
相关问题