帮我实现一个Todo App,要求界面美观
- User
帮我实现一个Todo App,要求界面美观
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
帮我实现一个Todo App,要求界面美观
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>优雅待办清单</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
padding: 40px;
width: 100%;
max-width: 500px;
backdrop-filter: blur(10px);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
font-size: 32px;
font-weight: 300;
letter-spacing: 2px;
}
.input-section {
display: flex;
gap: 10px;
margin-bottom: 30px;
}
#todoInput {
flex: 1;
padding: 15px 20px;
border: 2px solid #e0e0e0;
border-radius: 50px;
font-size: 16px;
outline: none;
transition: all 0.3s ease;
}
#todoInput:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
#addBtn {
padding: 15px 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 50px;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
#addBtn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
#addBtn:active {
transform: translateY(0);
}
.todo-list {
list-style: none;
}
.todo-item {
display: flex;
align-items: center;
padding: 15px 20px;
margin-bottom: 10px;
background: #f8f9fa;
border-radius: 10px;
transition: all 0.3s ease;
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.todo-item:hover {
transform: translateX(5px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.todo-item.completed {
opacity: 0.7;
}
.todo-item.completed .todo-text {
text-decoration: line-through;
color: #999;
}
.checkbox {
width: 24px;
height: 24px;
margin-right: 15px;
cursor: pointer;
accent-color: #667eea;
}
.todo-text {
flex: 1;
font-size: 16px;
color: #333;
word-break: break-word;
}
.delete-btn {
padding: 8px 16px;
background: #ff6b6b;
color: white;
border: none;
border-radius: 20px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
opacity: 0;
}
.todo-item:hover .delete-btn {
opacity: 1;
}
.delete-btn:hover {
background: #ff5252;
transform: scale(1.05);
}
.empty-state {
text-align: center;
color: #999;
padding: 40px;
font-size: 18px;
}
.stats {
display: flex;
justify-content: space-between;
margin-top: 30px;
padding: 20px;
background: #f8f9fa;
border-radius: 10px;
font-size: 14px;
color: #666;
}
.stats span {
font-weight: bold;
color: #667eea;
}
</style>
</head>
<body>
<div class="container">
<h1>✨ 我的待办清单</h1>
<div class="input-section">
<input type="text" id="todoInput" placeholder="添加新的待办事项..." maxlength="50">
<button id="addBtn">添加</button>
</div>
<ul class="todo-list" id="todoList">
<div class="empty-state">暂无待办事项,开始添加吧!</div>
</ul>
<div class="stats">
<div>总计: <span id="totalCount">0</span></div>
<div>已完成: <span id="completedCount">0</span></div>
<div>待完成: <span id="pendingCount">0</span></div>
</div>
</div>
<script>
let todos = JSON.parse(localStorage.getItem('todos')) || [];
const todoInput = document.getElementById('todoInput');
const addBtn = document.getElementById('addBtn');
const todoList = document.getElementById('todoList');
const totalCount = document.getElementById('totalCount');
const completedCount = document.getElementById('completedCount');
const pendingCount = document.getElementById('pendingCount');
function saveTodos() {
localStorage.setItem('todos', JSON.stringify(todos));
}
function updateStats() {
totalCount.textContent = todos.length;
completedCount.textContent = todos.filter(t => t.completed).length;
pendingCount.textContent = todos.filter(t => !t.completed).length;
}
function renderTodos() {
if (todos.length === 0) {
todoList.innerHTML = '<div class="empty-state">暂无待办事项,开始添加吧!</div>';
updateStats();
return;
}
todoList.innerHTML = '';
todos.forEach((todo, index) => {
const li = document.createElement('li');
li.className = 'todo-item';
if (todo.completed) li.classList.add('completed');
li.innerHTML = `
<input type="checkbox" class="checkbox" ${todo.completed ? 'checked' : ''}>
<span class="todo-text">${todo.text}</span>
<button class="delete-btn">删除</button>
`;
const checkbox = li.querySelector('.checkbox');
checkbox.addEventListener('change', () => toggleTodo(index));
const deleteBtn = li.querySelector('.delete-btn');
deleteBtn.addEventListener('click', () => deleteTodo(index));
todoList.appendChild(li);
});
updateStats();
}
function addTodo() {
const text = todoInput.value.trim();
if (text === '') return;
todos.unshift({
text,
completed: false,
id: Date.now()
});
todoInput.value = '';
saveTodos();
renderTodos();
}
function toggleTodo(index) {
todos[index].completed = !todos[index].completed;
saveTodos();
renderTodos();
}
function deleteTodo(index) {
todos.splice(index, 1);
saveTodos();
renderTodos();
}
addBtn.addEventListener('click', addTodo);
todoInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') addTodo();
});
renderTodos();
</script>
</body>
</html>