-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocalstorage3.html
More file actions
39 lines (36 loc) · 989 Bytes
/
localstorage3.html
File metadata and controls
39 lines (36 loc) · 989 Bytes
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
<html>
<head>
<meta charset="UTF-8">
<title>HTML5 page</title>
</head>
<body bgcolor="gray">
<center>
<input autofocus autocomplete="off" type="text" id="beniminputum">
<button id="btnSave" onclick="saveData()">Save</button>
<button onclick="localStorage.setItem('veriler','');showLS()">Clear</button>
<button onclick="showLS()">Contents</button>
<p>Contents:<br>
<pre id="contents"></pre>
<script>
function saveData(){
var lsNames = localStorage.getItem('veriler'),
arr = [];
if (!lsNames) { lsName = ''; } // initialize if null
arr = lsNames.split(',\n');
arr.push(document.getElementById("beniminputum").value);
lsNames = arr.join(',\n');
localStorage.setItem("veriler", lsNames);
showLS();
var resetButton = document.getElementById("beniminputum");
if(resetButton){
resetButton.value= "";
}
}
function showLS() {
var ls = localStorage.getItem('veriler');
document.getElementById('contents').innerHTML = "kayıtlı veriler:\n"+ls.substr(1);
}
</script>
</center>
</body>
</html>