<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Momentum App</title>
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<form id="login-form" class="hidden">
<input
required
maxlength="10"
type="text"
placeholder="What is your name?" />
<input type="submit" value="Log In" />
</form>
<h2 id="clock">00:00</h2>
<h1 id="greeting" class="hidden"></h1>
<form id="todo-form">
<input type="text" placeholder="Write a To Do and Press Enter" required/>
</form>
<ul id="todo-list"></ul>
<div id="quotes">
<span></span><br/>
<span></span>
</div>
<script src="JS/greetings.js"></script>
<script src="JS/clock.js"></script>
<script src="JS/Quotes.js"></script>
<script src="JS/background.js"></script>
<script src="JS/todo.js"></script>
</body>
</html>
JS
const todoForm = document.querySelector("#todo-form");
const todoList = document.querySelector("#todo-list");
const todoFormInput = todoForm.querySelector("input");
function handleToDoForm (e) {
e.preventDefault();
const newToDo = todoFormInput.value;
todoFormInput.value = "";
}
todoForm.addEventListener("submit", handleTodoForm);
function paintToDo(newTodo){
const li = document.createElement("li");
const span = document.createElement("span");
const button = document.createElement("button");
button.innerText = "❌";
span.innerText = newTodo;
li.appendChild(span);
li.appendChild(button);
todoList.appendChild(li);
}
function handleToDoForm (e) {
e.preventDefault();
const newTodo = todoFormInput.value;
todoFormInput.value = "";
paintToDo(newTodo);
}
결과:
function deleteToDo(e) {
const li = e.target.parentElement;
li.remove();
}
function paintToDo (newTodo) {
const li = document.createElement("li");
const span = document.createElement("span");
span.innerText = newTodo;
const button = document.createElement("button");
button.innerText = "❌";
button.addEventListener("click", deleteToDo);
li.appendChild(span);
li.appendChild(button);
toDoList.appendChild(li);
]
결과: