forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
43 lines (41 loc) · 1.43 KB
/
Copy pathindex.html
File metadata and controls
43 lines (41 loc) · 1.43 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do List</title>
<script>
// Function to add a new task
function addTask() {
const taskInput = document.getElementById('taskInput');
const taskValue = taskInput.value;
if (taskValue) {
const tasks = JSON.parse(localStorage.getItem('tasks')) || [];
tasks.push(taskValue);
localStorage.setItem('tasks', JSON.stringify(tasks));
taskInput.value = '';
renderTasks();
}
}
// Function to render tasks from local storage
function renderTasks() {
const tasks = JSON.parse(localStorage.getItem('tasks')) || [];
const taskList = document.getElementById('taskList');
taskList.innerHTML = '';
tasks.forEach((task, index) => {
const listItem = document.createElement('li');
listItem.textContent = task;
taskList.appendChild(listItem);
});
}
// Load tasks on page load
window.onload = renderTasks;
</script>
</head>
<body>
<h1>To-Do List</h1>
<input type="text" id="taskInput" placeholder="Add a new task" />
<button onclick="addTask()">Add Task</button>
<ul id="taskList"></ul>
</body>
</html>