-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
53 lines (50 loc) · 1.64 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Local Storage Example</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
label, .value-display {
display: block;
margin-top: 20px;
}
input[type="text"] {
padding: 8px;
font-size: 16px;
margin-top: 5px;
}
</style>
</head>
<body>
<h1>Local Storage Example</h1>
<div>
<label for="inputValue">Enter Value:</label>
<input type="text" id="inputValue" oninput="updateLocalStorage()" />
</div>
<div class="value-display">
<strong>Stored Value: </strong><span id="displayValue">undefined</span>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Function to display the value from local storage when the page loads
function displayValue() {
var storedValue = localStorage.getItem('myValue');
document.getElementById('displayValue').textContent = storedValue || 'undefined';
}
// Call the display function on page load
displayValue();
});
// Function to update local storage and the display
function updateLocalStorage() {
var inputValue = document.getElementById('inputValue').value;
localStorage.setItem('myValue', inputValue);
document.getElementById('displayValue').textContent = inputValue;
}
</script>
</body>
</html>