-
Notifications
You must be signed in to change notification settings - Fork 0
/
storageTime.html
59 lines (48 loc) · 1.68 KB
/
storageTime.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<html>
<head>
<title>Storage Time!</title>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(loadList);
function textToList()
{
var boxText = $('#abox').val();
$('#alist').append( "<li>" + boxText + "</li>" );
saveList();
}
function saveList()
{
var toSave = [];
$('li').each ( function (i,n) {
toSave.push($(n).text());
});
save (toSave);
}
function loadList()
{
myTextList = load('myText');
myTextList.forEach(function(element) {
$('#alist').append( "<li>" + element + "</li>" );
});
}
function save (saveMe)
{
var stringyThing = JSON.stringify(saveMe);
localStorage.setItem('myText', stringyThing);
}
function load (toLoad)
{
return JSON.parse(localStorage.getItem(toLoad));
}
</script>
</head>
<body>
<h1>Lets see how to save stuff!</h1>
<h2>Storage Time</h2>
<div>Type somehting into this box! <input type="text" id="abox"></div>
<div>Do the thing! ---> <button type="button" onclick="textToList()" id="abutton">Click Me!</button></div>
<h3>Even when you reload the page, this list will still be here!</h3>
<ul id="alist">
</ul>
</body>
</html>