forked from Berzeg07/learn-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.html
60 lines (52 loc) · 1.26 KB
/
todo.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
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<title>Learn JS</title>
</head>
<body>
<script src="js/jquery-1.12.0.min.js"></script>
<div class="container">
<input type="text" id="in">
<button id="add">Добавить</button>
<hr>
<div id="out"></div>
<!-- script -->
<script>
window.onload = function() {
var todoList = [];
if (localStorage.getItem('todo')!=undefined){
todoList = JSON.parse(localStorage.getItem('todo'));
out();
}
document.getElementById('add').onclick = function(){
var d = document.getElementById('in').value;
var temp = {};
temp.todo = d;
temp.check = false;
var i = todoList.length;
todoList[i] = temp;
console.log(todoList);
out();
localStorage.setItem('todo', JSON.stringify(todoList));
}
function out(){
var out='';
for (var key in todoList){
if (todoList[key].check == true) {
out += '<input type ="checkbox" checked />';
}
else{
out += '<input type ="checkbox" />';
}
out += todoList[key].todo + '<br />';
}
document.getElementById('out').innerHTML = out;
}
}
</script>
</div>
<!-- container -->
</body>
</html>