-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
102 lines (77 loc) · 2.8 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<title>List Kartun Lucuk</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
<div>
<div>
<div>
<h1>Input Disini</h1>
<input id="input-kartun" placeholder="Masukkan Nama" />
<button id="button" class="btn btn-success">Tambah
<i class="fa fa-heart"></i>
</button>
<br />
<br />
<ul id="list" class="list-group">
</ul>
</div>
<div>
<h1>Daftar Nama Kartun Lucuk</h1>
<p>Kami percaya Anda pernah melihat film kartun kartun yang lucuk lucuk.
<ol>
<li>Coba ketik nama kartun yang anda sukai.</li>
<li>Kemudian klik tambah.</li>
<li>Untuk menghapus klik list yang sydah anda input</li>
</ol>
</p>
<hr/>
<div>
<p>Di desain oleh M.Zaemakhrus</p>
<i>Semarang , 28 Juli 2018</i>
</div>
</div>
</div>
</div>
<script>
let data = [];
localData = JSON.parse(localStorage.getItem('data'));
if (localData != null) {
data = localData;
}
const inputDOM = document.getElementById('input-kartun');
// TODO
// buatlah variabel DOM untuk mengakses button
const buttonDOM = document.getElementById('button');
// buatlah variabel DOM untuk mengakses ol
const listDOM = document.getElementById('list');
// listDOM.innerHTML = localStorage.getItem('data');
buttonDOM.addEventListener('click', function () {
const kartun = inputDOM.value;
data.push(kartun);
render();
// listDOM.innerHTML = listDOM.innerHTML + "<li>" + kartun + "</li>";
inputDOM.value = "";
localStorage.setItem('data', JSON.stringify(data));
// alert('hello');
});
function render() {
let html = "";
for (var i = 0; i < data.length; i++) {
// html = html + "<li>" + data[i] + "</li>";
html = html + `<li class="list-group-item" onClick="remove(${i})" style="font-weight: bold;"><i class="fa fa-trash" style="color: #c90b0b;"></i> ${data[i]}</li>`;
}
listDOM.innerHTML = html;
}
render();
function remove(id) {
data.splice(id, 1);
localStorage.setItem('data', JSON.stringify(data));
render();
}
</script>
</body>
</html>