You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.7 KiB
81 lines
2.7 KiB
<!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>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
#todo-list {
|
|
margin-top: 20px;
|
|
}
|
|
.task {
|
|
margin-bottom: 10px;
|
|
}
|
|
.completed {
|
|
text-decoration: line-through;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>To-Do List</h1>
|
|
<p>What needs to be done? 222</p>
|
|
<input type="text" id="newTask" placeholder="Enter new task">
|
|
<button onclick="addTask()">Add</button>
|
|
|
|
<h2 id="completionStatus">0 out of 0 items completed</h2>
|
|
|
|
<div id="todo-list">
|
|
<!-- Tasks will be added here -->
|
|
</div>
|
|
|
|
<script>
|
|
function addTask() {
|
|
var taskList = document.getElementById('todo-list');
|
|
var newTask = document.getElementById('newTask');
|
|
var taskName = newTask.value.trim();
|
|
if (taskName !== '') {
|
|
var taskDiv = document.createElement('div');
|
|
taskDiv.className = 'task';
|
|
taskDiv.innerHTML = `
|
|
<input type="checkbox" class="task-checkbox" onclick="toggleCompletion(this)">
|
|
<span class="task-name">${taskName}</span>
|
|
<button onclick="editTask(this)">Edit</button>
|
|
<button onclick="deleteTask(this)">Delete</button>
|
|
`;
|
|
taskList.appendChild(taskDiv);
|
|
newTask.value = '';
|
|
updateCompletionStatus();
|
|
}
|
|
}
|
|
|
|
function toggleCompletion(checkbox) {
|
|
var taskName = checkbox.nextElementSibling;
|
|
taskName.classList.toggle('completed');
|
|
updateCompletionStatus();
|
|
}
|
|
|
|
function editTask(button) {
|
|
var taskName = button.previousElementSibling;
|
|
var newTaskName = prompt('Edit Name', taskName.textContent);
|
|
if (newTaskName !== null && newTaskName.trim() !== '') {
|
|
taskName.textContent = newTaskName;
|
|
}
|
|
}
|
|
|
|
function deleteTask(button) {
|
|
var taskDiv = button.parentElement;
|
|
taskDiv.parentElement.removeChild(taskDiv);
|
|
updateCompletionStatus();
|
|
}
|
|
|
|
function updateCompletionStatus() {
|
|
var tasks = document.querySelectorAll('.task');
|
|
var completedTasks = Array.from(tasks).filter(task => task.querySelector('.task-checkbox').checked).length;
|
|
document.getElementById('completionStatus').textContent = `${completedTasks} out of ${tasks.length} items completed`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |