-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
129 lines (121 loc) · 3.98 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!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 with Reminders</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 50px auto;
background-color: #ccc; /* Grey background color */
border-radius: 5px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.task-list {
list-style-type: none;
padding: 0;
}
.task {
display: flex;
align-items: center;
padding: 10px;
border-bottom: 1px solid #ccc;
}
.task.completed {
text-decoration: line-through;
opacity: 0.5;
}
.task input[type="checkbox"] {
margin-right: 10px;
}
.task input[type="text"], .task input[type="datetime-local"] {
flex: 1;
margin-right: 10px;
border: none;
padding: 5px;
border-radius: 3px;
}
.task button {
background-color: #ff6347;
color: #fff;
border: none;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
}
.task button:hover {
background-color: #e74c3c;
}
</style>
</head>
<body>
<div class="container">
<h2>To-Do List with Reminders</h2>
<form id="taskForm">
<input type="text" id="taskInput" placeholder="Add a new task...">
<input type="datetime-local" id="reminderInput">
<button type="submit">Add Task</button>
</form>
<ul class="task-list" id="taskList">
</ul>
<button onclick="deleteAllTasks()">Delete All Tasks</button>
</div>
<script>
const taskForm = document.getElementById('taskForm');
const taskInput = document.getElementById('taskInput');
const reminderInput = document.getElementById('reminderInput');
const taskList = document.getElementById('taskList');
taskForm.addEventListener('submit', addTask);
function addTask(event) {
event.preventDefault();
const taskText = taskInput.value.trim();
const reminderDateTime = reminderInput.value;
if (taskText !== '') {
const taskItem = document.createElement('li');
taskItem.className = 'task';
taskItem.innerHTML = `
<input type="checkbox" onchange="toggleTaskCompletion(this)">
<input type="text" value="${taskText}" readonly>
<input type="datetime-local" value="${reminderDateTime}" readonly>
<button onclick="editTask(this)">Edit</button>
<button onclick="deleteTask(this)">Delete</button>
`;
taskList.appendChild(taskItem);
taskInput.value = '';
reminderInput.value = '';
}
}
function toggleTaskCompletion(checkbox) {
const task = checkbox.parentElement;
if (checkbox.checked) {
task.classList.add('completed');
} else {
task.classList.remove('completed');
}
}
function editTask(button) {
const task = button.parentElement;
const textInput = task.querySelector('input[type="text"]');
const reminderInput = task.querySelector('input[type="datetime-local"]');
textInput.readOnly = false;
reminderInput.readOnly = false;
textInput.focus();
}
function deleteTask(button) {
const task = button.parentElement;
task.remove();
}
function deleteAllTasks() {
taskList.innerHTML = '';
}
</script>
</body>
</html>