2017-02-17 37 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' 
相關問題