|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>Todo App</title> |
|
<style> |
|
ul { |
|
list-style: none; |
|
padding: 0; |
|
} |
|
li { |
|
display: flex; |
|
align-items: center; |
|
margin-top: 10px; |
|
} |
|
input[type="checkbox"] { |
|
margin-right: 10px; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<h1>Todo App</h1> |
|
<textarea id="todo-input"></textarea> |
|
<button id="add-button">Add</button> |
|
<ul id="todo-list"></ul> |
|
<script> |
|
|
|
let todos = []; |
|
|
|
|
|
const input = document.getElementById("todo-input"); |
|
const addButton = document.getElementById("add-button"); |
|
const list = document.getElementById("todo-list"); |
|
|
|
|
|
function addTodo() { |
|
|
|
const todoText = input.value; |
|
|
|
|
|
todos.push({ |
|
text: todoText, |
|
completed: false |
|
}); |
|
|
|
|
|
input.value = ""; |
|
|
|
|
|
renderTodos(); |
|
} |
|
|
|
|
|
function renderTodos() { |
|
|
|
list.innerHTML = ""; |
|
|
|
|
|
for (const todo of todos) { |
|
|
|
const item = document.createElement("li"); |
|
|
|
|
|
const checkbox = document.createElement("input"); |
|
checkbox.type = "checkbox"; |
|
checkbox.checked = todo.completed; |
|
item.appendChild(checkbox); |
|
|
|
|
|
const text = document.createTextNode(todo.text); |
|
item.appendChild(text); |
|
|
|
|
|
list.appendChild(item); |
|
} |
|
} |
|
|
|
|
|
addButton.addEventListener("click", addTodo); |
|
</script> |
|
</body> |
|
</html> |
|
|