to do list
페이지 정보
본문
<!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;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
*/
.k_todo-container {
width: 900px;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.k_todo-container h1 {
font-size: 1.5rem;
margin-bottom: 10px;
}
.k_todo-input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 10px;
}
.k_todo-list {
list-style: none;
padding: 0;
margin: 0;
}
.k_todo-list li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #ddd;
}
.k_todo-list li:last-child {
border-bottom: none;
}
.k_todo-list .k_complete-btn,
.k_todo-list .k_delete-btn {
margin-left: 5px;
border: none;
border-radius: 4px;
padding: 5px 8px;
cursor: pointer;
}
.k_todo-list .k_complete-btn {
background: #2ecc71;
color: white;
}
.k_todo-list .k_delete-btn {
background: #e74c3c;
color: white;
}
.k_todo-list .k_completed {
text-decoration: line-through;
color: gray;
}
</style>
</head>
<body>
<div class="k_todo-container">
<h1>To-Do List</h1>
<input class="k_todo-input" type="text" placeholder="Enter a new task" />
<ul class="k_todo-list"></ul>
</div>
<script>
// Select elements
const todoInput = document.querySelector('.k_todo-input');
const todoList = document.querySelector('.k_todo-list');
// Function to add a new task
function addTodo(event) {
if (event.key === 'Enter' && todoInput.value.trim() !== '') {
const taskText = todoInput.value.trim();
// Create list item
const listItem = document.createElement('li');
// Task text
const taskSpan = document.createElement('span');
taskSpan.textContent = taskText;
// Complete button
const completeBtn = document.createElement('button');
completeBtn.textContent = 'Complete';
completeBtn.classList.add('k_complete-btn');
completeBtn.onclick = () => {
taskSpan.classList.toggle('k_completed');
};
// Delete button
const deleteBtn = document.createElement('button');
deleteBtn.textContent = 'Delete';
deleteBtn.classList.add('k_delete-btn');
deleteBtn.onclick = () => listItem.remove();
// Append buttons and text to list item
listItem.appendChild(taskSpan);
listItem.appendChild(completeBtn);
listItem.appendChild(deleteBtn);
// Append list item to the list
todoList.appendChild(listItem);
// Clear input field
todoInput.value = '';
}
}
// Add event listener to input
todoInput.addEventListener('keyup', addTodo);
</script>
</body>
</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;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
*/
.k_todo-container {
width: 900px;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.k_todo-container h1 {
font-size: 1.5rem;
margin-bottom: 10px;
}
.k_todo-input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 10px;
}
.k_todo-list {
list-style: none;
padding: 0;
margin: 0;
}
.k_todo-list li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #ddd;
}
.k_todo-list li:last-child {
border-bottom: none;
}
.k_todo-list .k_complete-btn,
.k_todo-list .k_delete-btn {
margin-left: 5px;
border: none;
border-radius: 4px;
padding: 5px 8px;
cursor: pointer;
}
.k_todo-list .k_complete-btn {
background: #2ecc71;
color: white;
}
.k_todo-list .k_delete-btn {
background: #e74c3c;
color: white;
}
.k_todo-list .k_completed {
text-decoration: line-through;
color: gray;
}
</style>
</head>
<body>
<div class="k_todo-container">
<h1>To-Do List</h1>
<input class="k_todo-input" type="text" placeholder="Enter a new task" />
<ul class="k_todo-list"></ul>
</div>
<script>
// Select elements
const todoInput = document.querySelector('.k_todo-input');
const todoList = document.querySelector('.k_todo-list');
// Function to add a new task
function addTodo(event) {
if (event.key === 'Enter' && todoInput.value.trim() !== '') {
const taskText = todoInput.value.trim();
// Create list item
const listItem = document.createElement('li');
// Task text
const taskSpan = document.createElement('span');
taskSpan.textContent = taskText;
// Complete button
const completeBtn = document.createElement('button');
completeBtn.textContent = 'Complete';
completeBtn.classList.add('k_complete-btn');
completeBtn.onclick = () => {
taskSpan.classList.toggle('k_completed');
};
// Delete button
const deleteBtn = document.createElement('button');
deleteBtn.textContent = 'Delete';
deleteBtn.classList.add('k_delete-btn');
deleteBtn.onclick = () => listItem.remove();
// Append buttons and text to list item
listItem.appendChild(taskSpan);
listItem.appendChild(completeBtn);
listItem.appendChild(deleteBtn);
// Append list item to the list
todoList.appendChild(listItem);
// Clear input field
todoInput.value = '';
}
}
// Add event listener to input
todoInput.addEventListener('keyup', addTodo);
</script>
</body>
</html>
To-Do List
- 이전글kims to to list 24.12.10
- 다음글Publish Online 24.10.20
댓글목록
등록된 댓글이 없습니다.