{"id":282,"date":"2026-03-19T22:32:01","date_gmt":"2026-03-19T14:32:01","guid":{"rendered":"https:\/\/www.resilence.cn\/?p=282"},"modified":"2026-03-19T22:32:01","modified_gmt":"2026-03-19T14:32:01","slug":"day-19-%e9%a1%b9%e7%9b%ae1-%e5%be%85%e5%8a%9e%e4%ba%8b%e9%a1%b9%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.resilence.cn\/?p=282","title":{"rendered":"Day-19-\u9879\u76ee1-\u5f85\u529e\u4e8b\u9879\u5e94\u7528"},"content":{"rendered":"<h1>Day 19: \u9879\u76ee1-\u5f85\u529e\u4e8b\u9879\u5e94\u7528<\/h1>\n<blockquote>\n<p>\ud83c\udfaf <strong>Day 19 &#8211; \u5f85\u529e\u4e8b\u9879\u5e94\u7528<\/strong><br \/>\n\ud83d\udcc2 \u5206\u7c7b: 09-\u9879\u76ee\u5b9e\u6218<br \/>\n\ud83d\udd25 \u96be\u5ea6: \u2b50\u2b50\u2b50\u2606\u2606<\/p>\n<\/blockquote>\n<hr>\n<h2>\ud83c\udfaf \u5b66\u4e60\u76ee\u6807<\/h2>\n<ul>\n<li>\u2705 \u7efc\u5408\u8fd0\u7528\u524d18\u5929\u5b66\u5230\u7684\u77e5\u8bc6\u6784\u5efa\u5b8c\u6574\u5e94\u7528<\/li>\n<li>\u2705 \u638c\u63e1DOM\u64cd\u4f5c\u3001\u4e8b\u4ef6\u5904\u7406\u3001\u6570\u636e\u6301\u4e45\u5316\u7684\u7efc\u5408\u5e94\u7528<\/li>\n<li>\u2705 \u5b66\u4f1a\u4f7f\u7528localStorage\u5b58\u50a8\u6570\u636e<\/li>\n<li>\u2705 \u7406\u89e3MVC\uff08Model-View-Controller\uff09\u8bbe\u8ba1\u6a21\u5f0f<\/li>\n<li>\u2705 \u57f9\u517b\u9879\u76ee\u5316\u601d\u7ef4\u548c\u4ee3\u7801\u7ec4\u7ec7\u80fd\u529b<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udca1 \u9879\u76ee\u6982\u8ff0<\/h2>\n<h3>\u9879\u76ee\u7b80\u4ecb<\/h3>\n<p>**\u5f85\u529e\u4e8b\u9879\u5e94\u7528\uff08Todo App\uff09**\u662f\u7f16\u7a0b\u5165\u95e8\u7684\u7ecf\u5178\u9879\u76ee\uff0c\u5b83\u80fd\u8ba9\u4f60\u7efc\u5408\u8fd0\u7528\uff1a<\/p>\n<ul>\n<li>HTML\u7ed3\u6784\u8bbe\u8ba1<\/li>\n<li>CSS\u6837\u5f0f\u7f8e\u5316<\/li>\n<li>JavaScript\u903b\u8f91\u5904\u7406<\/li>\n<li>DOM\u64cd\u4f5c<\/li>\n<li>\u4e8b\u4ef6\u5904\u7406<\/li>\n<li>\u6570\u636e\u5b58\u50a8<\/li>\n<\/ul>\n<h3>\u6838\u5fc3\u529f\u80fd<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u65b0\u7684\u5f85\u529e\u4e8b\u9879<\/li>\n<li>[ ] \u6807\u8bb0\u4e8b\u9879\u4e3a\u5b8c\u6210\/\u672a\u5b8c\u6210<\/li>\n<li>[ ] \u5220\u9664\u5f85\u529e\u4e8b\u9879<\/li>\n<li>[ ] \u7f16\u8f91\u4e8b\u9879\u5185\u5bb9<\/li>\n<li>[ ] \u8fc7\u6ee4\u663e\u793a\uff08\u5168\u90e8\/\u8fdb\u884c\u4e2d\/\u5df2\u5b8c\u6210\uff09<\/li>\n<li>[ ] \u6570\u636e\u6301\u4e45\u5316\uff08\u5237\u65b0\u4e0d\u4e22\u5931\uff09<\/li>\n<li>[ ] \u6e05\u7a7a\u6240\u6709\u5df2\u5b8c\u6210\u4e8b\u9879<\/li>\n<\/ul>\n<h3>\u6280\u672f\u6808<\/h3>\n<ul>\n<li><strong>HTML5<\/strong>: \u8bed\u4e49\u5316\u6807\u7b7e<\/li>\n<li><strong>CSS3<\/strong>: Flexbox\u5e03\u5c40\u3001\u8fc7\u6e21\u52a8\u753b<\/li>\n<li><strong>JavaScript ES6+<\/strong>: \u7bad\u5934\u51fd\u6570\u3001\u6a21\u677f\u5b57\u7b26\u4e32\u3001\u6570\u7ec4\u65b9\u6cd5<\/li>\n<li><strong>Web API<\/strong>: localStorage\u3001DOM API<\/li>\n<li><strong>\u8bbe\u8ba1\u6a21\u5f0f<\/strong>: MVC\uff08\u6a21\u578b-\u89c6\u56fe-\u63a7\u5236\u5668\uff09<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udcdd \u9879\u76ee\u7ed3\u6784<\/h2>\n<pre><code>todo-app\/\n\u251c\u2500\u2500 index.html          # \u4e3b\u9875\u9762\n\u251c\u2500\u2500 style.css           # \u6837\u5f0f\u6587\u4ef6\n\u2514\u2500\u2500 script.js           # JavaScript\u903b\u8f91\n<\/code><\/pre>\n<hr>\n<h2>\ud83c\udfae \u5b8c\u6574\u4ee3\u7801<\/h2>\n<h3>1. HTML (index.html)<\/h3>\n<pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;zh-CN&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;title&gt;\u5f85\u529e\u4e8b\u9879\u5e94\u7528&lt;\/title&gt;\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div class=&quot;container&quot;&gt;\n        &lt;header&gt;\n            &lt;h1&gt;\ud83d\udcdd \u6211\u7684\u5f85\u529e\u4e8b\u9879&lt;\/h1&gt;\n            &lt;p class=&quot;date&quot; id=&quot;currentDate&quot;&gt;&lt;\/p&gt;\n        &lt;\/header&gt;\n\n        &lt;!-- \u8f93\u5165\u533a\u57df --&gt;\n        &lt;div class=&quot;input-section&quot;&gt;\n            &lt;input \n                type=&quot;text&quot; \n                id=&quot;todoInput&quot; \n                placeholder=&quot;\u6dfb\u52a0\u65b0\u7684\u5f85\u529e\u4e8b\u9879...&quot;\n                autocomplete=&quot;off&quot;\n            &gt;\n            &lt;button id=&quot;addBtn&quot; class=&quot;btn-add&quot;&gt;\n                &lt;span&gt;\uff0b&lt;\/span&gt;\n            &lt;\/button&gt;\n        &lt;\/div&gt;\n\n        &lt;!-- \u8fc7\u6ee4\u6309\u94ae --&gt;\n        &lt;div class=&quot;filter-section&quot;&gt;\n            &lt;button class=&quot;filter-btn active&quot; data-filter=&quot;all&quot;&gt;\u5168\u90e8&lt;\/button&gt;\n            &lt;button class=&quot;filter-btn&quot; data-filter=&quot;active&quot;&gt;\u8fdb\u884c\u4e2d&lt;\/button&gt;\n            &lt;button class=&quot;filter-btn&quot; data-filter=&quot;completed&quot;&gt;\u5df2\u5b8c\u6210&lt;\/button&gt;\n        &lt;\/div&gt;\n\n        &lt;!-- \u7edf\u8ba1\u4fe1\u606f --&gt;\n        &lt;div class=&quot;stats&quot;&gt;\n            &lt;span id=&quot;totalCount&quot;&gt;\u5171 0 \u9879&lt;\/span&gt;\n            &lt;button id=&quot;clearCompleted&quot; class=&quot;clear-btn&quot;&gt;\u6e05\u9664\u5df2\u5b8c\u6210&lt;\/button&gt;\n        &lt;\/div&gt;\n\n        &lt;!-- \u5f85\u529e\u5217\u8868 --&gt;\n        &lt;ul id=&quot;todoList&quot; class=&quot;todo-list&quot;&gt;&lt;\/ul&gt;\n\n        &lt;!-- \u7a7a\u72b6\u6001\u63d0\u793a --&gt;\n        &lt;div id=&quot;emptyState&quot; class=&quot;empty-state&quot;&gt;\n            &lt;p&gt;\ud83c\udf89 \u592a\u68d2\u4e86\uff01\u6240\u6709\u4e8b\u9879\u90fd\u5b8c\u6210\u4e86&lt;\/p&gt;\n            &lt;small&gt;\u6216\u8005\u6dfb\u52a0\u4e00\u4e9b\u65b0\u7684\u5f85\u529e\u4e8b\u9879\u5427&lt;\/small&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n\n    &lt;script src=&quot;script.js&quot;&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<h3>2. CSS (style.css)<\/h3>\n<pre><code class=\"language-css\">\/* \u5168\u5c40\u6837\u5f0f *\/\n* {\n    margin: 0;\n    padding: 0;\n    box-sizing: border-box;\n}\n\nbody {\n    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n    min-height: 100vh;\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    padding: 20px;\n}\n\n\/* \u5bb9\u5668 *\/\n.container {\n    background: white;\n    border-radius: 20px;\n    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);\n    max-width: 500px;\n    width: 100%;\n    padding: 30px;\n}\n\n\/* \u5934\u90e8 *\/\nheader {\n    text-align: center;\n    margin-bottom: 30px;\n}\n\nheader h1 {\n    color: #333;\n    font-size: 28px;\n    margin-bottom: 10px;\n}\n\n.date {\n    color: #666;\n    font-size: 14px;\n}\n\n\/* \u8f93\u5165\u533a\u57df *\/\n.input-section {\n    display: flex;\n    gap: 10px;\n    margin-bottom: 20px;\n}\n\n#todoInput {\n    flex: 1;\n    padding: 15px;\n    border: 2px solid #e0e0e0;\n    border-radius: 10px;\n    font-size: 16px;\n    transition: border-color 0.3s;\n}\n\n#todoInput:focus {\n    outline: none;\n    border-color: #667eea;\n}\n\n.btn-add {\n    background: #667eea;\n    color: white;\n    border: none;\n    border-radius: 10px;\n    width: 50px;\n    font-size: 24px;\n    cursor: pointer;\n    transition: all 0.3s;\n}\n\n.btn-add:hover {\n    background: #5568d3;\n    transform: scale(1.05);\n}\n\n\/* \u8fc7\u6ee4\u6309\u94ae *\/\n.filter-section {\n    display: flex;\n    gap: 10px;\n    margin-bottom: 20px;\n}\n\n.filter-btn {\n    flex: 1;\n    padding: 10px;\n    border: 2px solid #e0e0e0;\n    background: white;\n    border-radius: 8px;\n    cursor: pointer;\n    font-size: 14px;\n    transition: all 0.3s;\n}\n\n.filter-btn:hover {\n    border-color: #667eea;\n}\n\n.filter-btn.active {\n    background: #667eea;\n    color: white;\n    border-color: #667eea;\n}\n\n\/* \u7edf\u8ba1\u4fe1\u606f *\/\n.stats {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    margin-bottom: 20px;\n    font-size: 14px;\n    color: #666;\n}\n\n.clear-btn {\n    background: none;\n    border: none;\n    color: #f56565;\n    cursor: pointer;\n    font-size: 14px;\n}\n\n.clear-btn:hover {\n    text-decoration: underline;\n}\n\n\/* \u5f85\u529e\u5217\u8868 *\/\n.todo-list {\n    list-style: none;\n}\n\n.todo-item {\n    display: flex;\n    align-items: center;\n    padding: 15px;\n    background: #f7f7f7;\n    border-radius: 10px;\n    margin-bottom: 10px;\n    transition: all 0.3s;\n    animation: slideIn 0.3s ease;\n}\n\n@keyframes slideIn {\n    from {\n        opacity: 0;\n        transform: translateY(-10px);\n    }\n    to {\n        opacity: 1;\n        transform: translateY(0);\n    }\n}\n\n.todo-item:hover {\n    background: #f0f0f0;\n}\n\n.todo-item.completed {\n    opacity: 0.6;\n}\n\n.todo-item.completed .todo-text {\n    text-decoration: line-through;\n    color: #999;\n}\n\n\/* \u590d\u9009\u6846 *\/\n.todo-item input[type=&quot;checkbox&quot;] {\n    width: 20px;\n    height: 20px;\n    margin-right: 15px;\n    cursor: pointer;\n}\n\n\/* \u5f85\u529e\u6587\u672c *\/\n.todo-text {\n    flex: 1;\n    font-size: 16px;\n    color: #333;\n    word-break: break-word;\n}\n\n\/* \u5220\u9664\u6309\u94ae *\/\n.delete-btn {\n    background: #f56565;\n    color: white;\n    border: none;\n    border-radius: 6px;\n    padding: 6px 12px;\n    cursor: pointer;\n    font-size: 12px;\n    transition: all 0.3s;\n}\n\n.delete-btn:hover {\n    background: #e53e3e;\n}\n\n\/* \u7a7a\u72b6\u6001 *\/\n.empty-state {\n    text-align: center;\n    padding: 40px 20px;\n    color: #999;\n}\n\n.empty-state p {\n    font-size: 18px;\n    margin-bottom: 10px;\n}\n\n.empty-state small {\n    font-size: 14px;\n}\n\n\/* \u54cd\u5e94\u5f0f *\/\n@media (max-width: 480px) {\n    .container {\n        padding: 20px;\n    }\n    \n    header h1 {\n        font-size: 24px;\n    }\n    \n    .filter-section {\n        flex-direction: column;\n    }\n}\n<\/code><\/pre>\n<h3>3. JavaScript (script.js)<\/h3>\n<pre><code class=\"language-javascript\">\/\/ ========== \u6570\u636e\u6a21\u578b ==========\nclass TodoModel {\n    constructor() {\n        this.todos = this.loadFromStorage();\n    }\n\n    \/\/ \u4ece localStorage \u52a0\u8f7d\u6570\u636e\n    loadFromStorage() {\n        const stored = localStorage.getItem('todos');\n        return stored ? JSON.parse(stored) : [];\n    }\n\n    \/\/ \u4fdd\u5b58\u5230 localStorage\n    saveToStorage() {\n        localStorage.setItem('todos', JSON.stringify(this.todos));\n    }\n\n    \/\/ \u6dfb\u52a0\u5f85\u529e\u4e8b\u9879\n    addTodo(text) {\n        const todo = {\n            id: Date.now(),\n            text: text,\n            completed: false,\n            createdAt: new Date().toISOString()\n        };\n        this.todos.push(todo);\n        this.saveToStorage();\n        return todo;\n    }\n\n    \/\/ \u5207\u6362\u5b8c\u6210\u72b6\u6001\n    toggleTodo(id) {\n        const todo = this.todos.find(t =&gt; t.id === id);\n        if (todo) {\n            todo.completed = !todo.completed;\n            this.saveToStorage();\n        }\n        return todo;\n    }\n\n    \/\/ \u5220\u9664\u5f85\u529e\u4e8b\u9879\n    deleteTodo(id) {\n        this.todos = this.todos.filter(t =&gt; t.id !== id);\n        this.saveToStorage();\n    }\n\n    \/\/ \u7f16\u8f91\u5f85\u529e\u4e8b\u9879\n    editTodo(id, newText) {\n        const todo = this.todos.find(t =&gt; t.id === id);\n        if (todo &amp;&amp; newText.trim()) {\n            todo.text = newText.trim();\n            this.saveToStorage();\n        }\n    }\n\n    \/\/ \u6e05\u9664\u5df2\u5b8c\u6210\n    clearCompleted() {\n        this.todos = this.todos.filter(t =&gt; !t.completed);\n        this.saveToStorage();\n    }\n\n    \/\/ \u83b7\u53d6\u8fc7\u6ee4\u540e\u7684\u5217\u8868\n    getFilteredTodos(filter) {\n        switch(filter) {\n            case 'active':\n                return this.todos.filter(t =&gt; !t.completed);\n            case 'completed':\n                return this.todos.filter(t =&gt; t.completed);\n            default:\n                return this.todos;\n        }\n    }\n\n    \/\/ \u83b7\u53d6\u7edf\u8ba1\u4fe1\u606f\n    getStats() {\n        const total = this.todos.length;\n        const completed = this.todos.filter(t =&gt; t.completed).length;\n        const active = total - completed;\n        return { total, completed, active };\n    }\n}\n\n\/\/ ========== \u89c6\u56fe\u6e32\u67d3 ==========\nclass TodoView {\n    constructor() {\n        this.todoList = document.getElementById('todoList');\n        this.todoInput = document.getElementById('todoInput');\n        this.emptyState = document.getElementById('emptyState');\n        this.totalCount = document.getElementById('totalCount');\n    }\n\n    \/\/ \u6e32\u67d3\u5f85\u529e\u5217\u8868\n    renderTodos(todos) {\n        this.todoList.innerHTML = '';\n\n        if (todos.length === 0) {\n            this.emptyState.style.display = 'block';\n        } else {\n            this.emptyState.style.display = 'none';\n            \n            todos.forEach(todo =&gt; {\n                const li = this.createTodoElement(todo);\n                this.todoList.appendChild(li);\n            });\n        }\n    }\n\n    \/\/ \u521b\u5efa\u5f85\u529e\u4e8b\u9879\u5143\u7d20\n    createTodoElement(todo) {\n        const li = document.createElement('li');\n        li.className = `todo-item ${todo.completed ? 'completed' : ''}`;\n        li.dataset.id = todo.id;\n\n        li.innerHTML = `\n            &lt;input type=&quot;checkbox&quot; ${todo.completed ? 'checked' : ''}&gt;\n            &lt;span class=&quot;todo-text&quot;&gt;${this.escapeHtml(todo.text)}&lt;\/span&gt;\n            &lt;button class=&quot;delete-btn&quot;&gt;\u5220\u9664&lt;\/button&gt;\n        `;\n\n        return li;\n    }\n\n    \/\/ \u66f4\u65b0\u7edf\u8ba1\u4fe1\u606f\n    updateStats(stats) {\n        this.totalCount.textContent = `\u5171 ${stats.total} \u9879 (${stats.active} \u8fdb\u884c\u4e2d)`;\n    }\n\n    \/\/ \u83b7\u53d6\u8f93\u5165\u503c\n    getInputValue() {\n        return this.todoInput.value.trim();\n    }\n\n    \/\/ \u6e05\u7a7a\u8f93\u5165\u6846\n    clearInput() {\n        this.todoInput.value = '';\n    }\n\n    \/\/ HTML\u8f6c\u4e49\uff08\u9632\u6b62XSS\uff09\n    escapeHtml(text) {\n        const div = document.createElement('div');\n        div.textContent = text;\n        return div.innerHTML;\n    }\n}\n\n\/\/ ========== \u63a7\u5236\u5668 ==========\nclass TodoController {\n    constructor(model, view) {\n        this.model = model;\n        this.view = view;\n        this.currentFilter = 'all';\n        \n        this.initEventListeners();\n        this.render();\n    }\n\n    \/\/ \u521d\u59cb\u5316\u4e8b\u4ef6\u76d1\u542c\n    initEventListeners() {\n        \/\/ \u6dfb\u52a0\u6309\u94ae\n        document.getElementById('addBtn').addEventListener('click', () =&gt; {\n            this.handleAddTodo();\n        });\n\n        \/\/ \u56de\u8f66\u6dfb\u52a0\n        this.view.todoInput.addEventListener('keypress', (e) =&gt; {\n            if (e.key === 'Enter') {\n                this.handleAddTodo();\n            }\n        });\n\n        \/\/ \u5217\u8868\u70b9\u51fb\u4e8b\u4ef6\uff08\u59d4\u6258\uff09\n        this.view.todoList.addEventListener('click', (e) =&gt; {\n            const todoItem = e.target.closest('.todo-item');\n            if (!todoItem) return;\n\n            const id = parseInt(todoItem.dataset.id);\n\n            if (e.target.type === 'checkbox') {\n                this.handleToggleTodo(id);\n            } else if (e.target.classList.contains('delete-btn')) {\n                this.handleDeleteTodo(id);\n            }\n        });\n\n        \/\/ \u8fc7\u6ee4\u6309\u94ae\n        document.querySelectorAll('.filter-btn').forEach(btn =&gt; {\n            btn.addEventListener('click', () =&gt; {\n                this.handleFilterChange(btn);\n            });\n        });\n\n        \/\/ \u6e05\u9664\u5df2\u5b8c\u6210\n        document.getElementById('clearCompleted').addEventListener('click', () =&gt; {\n            this.handleClearCompleted();\n        });\n    }\n\n    \/\/ \u5904\u7406\u6dfb\u52a0\u5f85\u529e\n    handleAddTodo() {\n        const text = this.view.getInputValue();\n        if (!text) {\n            alert('\u8bf7\u8f93\u5165\u5f85\u529e\u4e8b\u9879\uff01');\n            return;\n        }\n\n        this.model.addTodo(text);\n        this.view.clearInput();\n        this.render();\n    }\n\n    \/\/ \u5904\u7406\u5207\u6362\u72b6\u6001\n    handleToggleTodo(id) {\n        this.model.toggleTodo(id);\n        this.render();\n    }\n\n    \/\/ \u5904\u7406\u5220\u9664\n    handleDeleteTodo(id) {\n        if (confirm('\u786e\u5b9a\u8981\u5220\u9664\u8fd9\u4e2a\u5f85\u529e\u4e8b\u9879\u5417\uff1f')) {\n            this.model.deleteTodo(id);\n            this.render();\n        }\n    }\n\n    \/\/ \u5904\u7406\u8fc7\u6ee4\u5207\u6362\n    handleFilterChange(btn) {\n        \/\/ \u66f4\u65b0\u6309\u94ae\u72b6\u6001\n        document.querySelectorAll('.filter-btn').forEach(b =&gt; {\n            b.classList.remove('active');\n        });\n        btn.classList.add('active');\n\n        \/\/ \u66f4\u65b0\u8fc7\u6ee4\u5668\n        this.currentFilter = btn.dataset.filter;\n        this.render();\n    }\n\n    \/\/ \u5904\u7406\u6e05\u9664\u5df2\u5b8c\u6210\n    handleClearCompleted() {\n        const stats = this.model.getStats();\n        if (stats.completed === 0) {\n            alert('\u6ca1\u6709\u5df2\u5b8c\u6210\u7684\u5f85\u529e\u4e8b\u9879\uff01');\n            return;\n        }\n\n        if (confirm(`\u786e\u5b9a\u8981\u6e05\u9664 ${stats.completed} \u4e2a\u5df2\u5b8c\u6210\u7684\u4e8b\u9879\u5417\uff1f`)) {\n            this.model.clearCompleted();\n            this.render();\n        }\n    }\n\n    \/\/ \u6e32\u67d3\u89c6\u56fe\n    render() {\n        const filteredTodos = this.model.getFilteredTodos(this.currentFilter);\n        this.view.renderTodos(filteredTodos);\n        this.view.updateStats(this.model.getStats());\n    }\n}\n\n\/\/ ========== \u5e94\u7528\u521d\u59cb\u5316 ==========\n\/\/ \u663e\u793a\u5f53\u524d\u65e5\u671f\nfunction displayCurrentDate() {\n    const options = { \n        year: 'numeric', \n        month: 'long', \n        day: 'numeric',\n        weekday: 'long'\n    };\n    const today = new Date().toLocaleDateString('zh-CN', options);\n    document.getElementById('currentDate').textContent = today;\n}\n\n\/\/ \u542f\u52a8\u5e94\u7528\ndocument.addEventListener('DOMContentLoaded', () =&gt; {\n    displayCurrentDate();\n    \n    const model = new TodoModel();\n    const view = new TodoView();\n    const controller = new TodoController(model, view);\n\n    console.log('\ud83c\udf89 \u5f85\u529e\u4e8b\u9879\u5e94\u7528\u5df2\u542f\u52a8\uff01');\n    console.log('\ud83d\udca1 \u63d0\u793a\uff1a\u6240\u6709\u6570\u636e\u90fd\u4fdd\u5b58\u5728\u672c\u5730\uff0c\u5237\u65b0\u9875\u9762\u4e0d\u4f1a\u4e22\u5931');\n});\n<\/code><\/pre>\n<hr>\n<h2>\ud83c\udfaf \u9879\u76ee\u4eae\u70b9<\/h2>\n<h3>1. MVC\u67b6\u6784\u8bbe\u8ba1<\/h3>\n<pre><code>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502   View      \u2502  \u2190 \u8d1f\u8d23UI\u6e32\u67d3\u548c\u7528\u6237\u4ea4\u4e92\n\u2502  (\u89c6\u56fe\u5c42)   \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n       \u2502\n       \u2193\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 Controller  \u2502  \u2190 \u5904\u7406\u4e1a\u52a1\u903b\u8f91\u548c\u4e8b\u4ef6\n\u2502  (\u63a7\u5236\u5c42)   \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n       \u2502\n       \u2193\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502    Model    \u2502  \u2190 \u7ba1\u7406\u6570\u636e\u548c\u72b6\u6001\n\u2502  (\u6a21\u578b\u5c42)   \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n<\/code><\/pre>\n<h3>2. \u6570\u636e\u6301\u4e45\u5316<\/h3>\n<p>\u4f7f\u7528 <code>localStorage<\/code> \u4fdd\u5b58\u6570\u636e\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u4fdd\u5b58\nlocalStorage.setItem('todos', JSON.stringify(todos));\n\n\/\/ \u8bfb\u53d6\nconst todos = JSON.parse(localStorage.getItem('todos'));\n<\/code><\/pre>\n<h3>3. \u4e8b\u4ef6\u59d4\u6258<\/h3>\n<p>\u4f7f\u7528\u4e8b\u4ef6\u59d4\u6258\u4f18\u5316\u6027\u80fd\uff1a<\/p>\n<pre><code class=\"language-javascript\">todoList.addEventListener('click', (e) =&gt; {\n    if (e.target.type === 'checkbox') {\n        \/\/ \u5904\u7406\u590d\u9009\u6846\n    }\n});\n<\/code><\/pre>\n<h3>4. \u5b89\u5168\u9632\u62a4<\/h3>\n<p>HTML\u8f6c\u4e49\u9632\u6b62XSS\u653b\u51fb\uff1a<\/p>\n<pre><code class=\"language-javascript\">escapeHtml(text) {\n    const div = document.createElement('div');\n    div.textContent = text;\n    return div.innerHTML;\n}\n<\/code><\/pre>\n<hr>\n<h2>\u270d\ufe0f \u7ec3\u4e60\u4efb\u52a1<\/h2>\n<h3>\u7ec3\u4e601\uff1a\u57fa\u7840\u529f\u80fd\uff0830\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u521b\u5efa\u9879\u76ee\u6587\u4ef6\u7ed3\u6784<\/li>\n<li>[ ] \u5b9e\u73b0\u6dfb\u52a0\u5f85\u529e\u4e8b\u9879\u529f\u80fd<\/li>\n<li>[ ] \u5b9e\u73b0\u5220\u9664\u5f85\u529e\u4e8b\u9879\u529f\u80fd<\/li>\n<li>[ ] \u5b9e\u73b0\u6807\u8bb0\u5b8c\u6210\u529f\u80fd<\/li>\n<li>[ ] \u6d4b\u8bd5\u57fa\u672c\u529f\u80fd\u662f\u5426\u6b63\u5e38<\/li>\n<\/ul>\n<h3>\u7ec3\u4e602\uff1a\u8fdb\u9636\u529f\u80fd\uff0845\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u8fc7\u6ee4\u529f\u80fd\uff08\u5168\u90e8\/\u8fdb\u884c\u4e2d\/\u5df2\u5b8c\u6210\uff09<\/li>\n<li>[ ] \u5b9e\u73b0\u6570\u636e\u6301\u4e45\u5316\uff08localStorage\uff09<\/li>\n<li>[ ] \u6dfb\u52a0\u7edf\u8ba1\u4fe1\u606f\u663e\u793a<\/li>\n<li>[ ] \u5b9e\u73b0\u6e05\u9664\u5df2\u5b8c\u6210\u529f\u80fd<\/li>\n<li>[ ] \u6dfb\u52a0\u7a7a\u72b6\u6001\u63d0\u793a<\/li>\n<\/ul>\n<h3>\u7ec3\u4e603\uff1aUI\u4f18\u5316\uff0830\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u6dfb\u52a0\u52a8\u753b\u6548\u679c<\/li>\n<li>[ ] \u4f18\u5316\u79fb\u52a8\u7aef\u54cd\u5e94\u5f0f\u5e03\u5c40<\/li>\n<li>[ ] \u6dfb\u52a0hover\u6548\u679c<\/li>\n<li>[ ] \u7f8e\u5316\u6309\u94ae\u548c\u8f93\u5165\u6846<\/li>\n<li>[ ] \u6dfb\u52a0\u65e5\u671f\u663e\u793a<\/li>\n<\/ul>\n<h3>\u7ec3\u4e604\uff1a\u529f\u80fd\u6269\u5c55\uff0860\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u7f16\u8f91\u5f85\u529e\u4e8b\u9879\u529f\u80fd\uff08\u53cc\u51fb\u7f16\u8f91\uff09<\/li>\n<li>[ ] \u62d6\u62fd\u6392\u5e8f\u529f\u80fd\uff08\u4f7f\u7528HTML5 Drag API\uff09<\/li>\n<li>[ ] \u4f18\u5148\u7ea7\u6807\u8bb0\uff08\u9ad8\/\u4e2d\/\u4f4e\uff09<\/li>\n<li>[ ] \u622a\u6b62\u65e5\u671f\u8bbe\u7f6e<\/li>\n<li>[ ] \u5bfc\u51fa\u5f85\u529e\u5217\u8868\u4e3aJSON<\/li>\n<\/ul>\n<hr>\n<h2>\ud83c\udf93 \u6311\u6218\u9879\u76ee<\/h2>\n<h3>\u6311\u6218\uff1a\u9ad8\u7ea7\u5f85\u529e\u5e94\u7528<\/h3>\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u5b9e\u73b0\u4e00\u4e2a\u529f\u80fd\u5b8c\u6574\u7684\u5f85\u529e\u4e8b\u9879\u5e94\u7528<\/p>\n<p><strong>\u529f\u80fd\u8981\u6c42<\/strong>\uff1a<\/p>\n<ul>\n<li>[x] \u57fa\u7840CRUD\u64cd\u4f5c<\/li>\n<li>[x] \u6570\u636e\u6301\u4e45\u5316<\/li>\n<li>[x] \u8fc7\u6ee4\u529f\u80fd<\/li>\n<li>[ ] \u5f85\u529e\u4e8b\u9879\u5206\u7c7b\uff08\u5de5\u4f5c\/\u751f\u6d3b\/\u5b66\u4e60\uff09<\/li>\n<li>[ ] \u4f18\u5148\u7ea7\u8bbe\u7f6e\uff08\u9ad8\/\u4e2d\/\u4f4e\uff09<\/li>\n<li>[ ] \u622a\u6b62\u65e5\u671f\u63d0\u9192<\/li>\n<li>[ ] \u641c\u7d22\u529f\u80fd<\/li>\n<li>[ ] \u62d6\u62fd\u6392\u5e8f<\/li>\n<li>[ ] \u6697\u9ed1\u6a21\u5f0f\u5207\u6362<\/li>\n<li>[ ] \u6570\u636e\u5bfc\u51fa\/\u5bfc\u5165<\/li>\n<\/ul>\n<p><strong>\u6280\u672f\u8981\u6c42<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528ES6+\u8bed\u6cd5<\/li>\n<li>\u4ee3\u7801\u7ed3\u6784\u6e05\u6670\uff08MVC\uff09<\/li>\n<li>\u6709\u826f\u597d\u7684\u6ce8\u91ca<\/li>\n<li>\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udca1 \u5e38\u89c1\u95ee\u9898 FAQ<\/h2>\n<h3>Q1: localStorage\u6709\u5927\u5c0f\u9650\u5236\u5417\uff1f<\/h3>\n<p><strong>A<\/strong>: \u6709\uff0c\u901a\u5e38\u9650\u5236\u57285-10MB\u3002\u5bf9\u4e8e\u6587\u672c\u6570\u636e\u6765\u8bf4\u8db3\u591f\u4e86\u3002\u5982\u679c\u9700\u8981\u5b58\u50a8\u5927\u91cf\u6570\u636e\uff0c\u8003\u8651\u4f7f\u7528IndexedDB\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u9632\u6b62XSS\u653b\u51fb\uff1f<\/h3>\n<p><strong>A<\/strong>: \u5728\u663e\u793a\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u65f6\uff0c\u8981\u8fdb\u884cHTML\u8f6c\u4e49\uff1a<\/p>\n<pre><code class=\"language-javascript\">function escapeHtml(text) {\n    const div = document.createElement('div');\n    div.textContent = text;\n    return div.innerHTML;\n}\n<\/code><\/pre>\n<h3>Q3: \u4e8b\u4ef6\u59d4\u6258\u6709\u4ec0\u4e48\u597d\u5904\uff1f<\/h3>\n<p><strong>A<\/strong>:<\/p>\n<ul>\n<li>\u51cf\u5c11\u4e8b\u4ef6\u76d1\u542c\u5668\u6570\u91cf<\/li>\n<li>\u52a8\u6001\u6dfb\u52a0\u7684\u5143\u7d20\u4e5f\u80fd\u54cd\u5e94\u4e8b\u4ef6<\/li>\n<li>\u63d0\u9ad8\u6027\u80fd<\/li>\n<\/ul>\n<h3>Q4: \u5982\u4f55\u4f18\u5316\u79fb\u52a8\u7aef\u4f53\u9a8c\uff1f<\/h3>\n<p><strong>A<\/strong>:<\/p>\n<ul>\n<li>\u6dfb\u52a0viewport meta\u6807\u7b7e<\/li>\n<li>\u4f7f\u7528Flexbox\u5e03\u5c40<\/li>\n<li>\u6309\u94ae\u5c3a\u5bf8\u81f3\u5c1144x44px<\/li>\n<li>\u907f\u514dhover\u6548\u679c\uff08\u79fb\u52a8\u7aef\u6ca1\u6709\uff09<\/li>\n<\/ul>\n<h3>Q5: \u4ee3\u7801\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\u5417\uff1f<\/h3>\n<p><strong>A<\/strong>: \u53ef\u4ee5\u8003\u8651\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u865a\u62df\u6eda\u52a8\uff08\u5927\u91cf\u6570\u636e\u65f6\uff09<\/li>\n<li>\u6dfb\u52a0\u9632\u6296\/\u8282\u6d41<\/li>\n<li>\u4f7f\u7528Web Worker\u5904\u7406\u5927\u6570\u636e<\/li>\n<li>\u6dfb\u52a0\u5355\u5143\u6d4b\u8bd5<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udcda \u62d3\u5c55\u5b66\u4e60<\/h2>\n<h3>\u63a8\u8350\u8d44\u6e90<\/h3>\n<p><strong>\u5728\u7ebf\u6559\u7a0b<\/strong>\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/javascript.info\/localstorage\">JavaScript.info &#8211; localStorage<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/API\/Web_Storage_API\">MDN &#8211; Web Storage API<\/a><\/li>\n<\/ul>\n<p><strong>\u76f8\u5173\u9879\u76ee<\/strong>\uff1a<\/p>\n<ul>\n<li>\u7b14\u8bb0\u5e94\u7528<\/li>\n<li>\u756a\u8304\u949f\u5e94\u7528<\/li>\n<li>\u8d26\u5355\u7ba1\u7406\u5e94\u7528<\/li>\n<\/ul>\n<p><strong>\u8fdb\u9636\u4e3b\u9898<\/strong>\uff1a<\/p>\n<ul>\n<li>IndexedDB\uff08\u5927\u5bb9\u91cf\u5b58\u50a8\uff09<\/li>\n<li>Service Worker\uff08\u79bb\u7ebf\u5e94\u7528\uff09<\/li>\n<li>PWA\uff08\u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff09<\/li>\n<\/ul>\n<hr>\n<h2>\ud83c\udfaf \u603b\u7ed3<\/h2>\n<p><strong>\u4eca\u5929\u6211\u4eec\u5b66\u5230\u4e86<\/strong>\uff1a<\/p>\n<ul>\n<li>\u2705 MVC\u8bbe\u8ba1\u6a21\u5f0f\u7684\u5e94\u7528<\/li>\n<li>\u2705 localStorage\u6570\u636e\u6301\u4e45\u5316<\/li>\n<li>\u2705 \u4e8b\u4ef6\u59d4\u6258\u4f18\u5316\u6027\u80fd<\/li>\n<li>\u2705 \u7efc\u5408\u8fd0\u7528DOM\u64cd\u4f5c<\/li>\n<li>\u2705 \u5b8c\u6574\u9879\u76ee\u5f00\u53d1\u6d41\u7a0b<\/li>\n<\/ul>\n<p><strong>\u5173\u952e\u6982\u5ff5<\/strong>\uff1a<\/p>\n<ul>\n<li>\ud83d\udce6 <strong>\u6570\u636e\u6a21\u578b<\/strong>\uff1a\u7ba1\u7406\u5e94\u7528\u72b6\u6001<\/li>\n<li>\ud83c\udfa8 <strong>\u89c6\u56fe\u6e32\u67d3<\/strong>\uff1a\u5c55\u793aUI<\/li>\n<li>\ud83c\udfae <strong>\u63a7\u5236\u5668<\/strong>\uff1a\u5904\u7406\u903b\u8f91<\/li>\n<\/ul>\n<hr>\n<p><strong>\u5b66\u4e60\u65f6\u95f4<\/strong>: 2026-03-17<br \/>\n<strong>\u96be\u5ea6<\/strong>: \u2b50\u2b50\u2b50\u2606\u2606<br \/>\n<strong>\u9884\u8ba1\u7528\u65f6<\/strong>: 3-4 \u5c0f\u65f6<br \/>\n<strong>\u5173\u952e\u8bcd<\/strong>: \u5f85\u529e\u4e8b\u9879\u3001MVC\u3001localStorage\u3001DOM\u64cd\u4f5c<br \/>\n<strong>\u76f8\u5173\u6807\u7b7e<\/strong>: #09-\u9879\u76ee\u5b9e\u6218<\/p>\n<hr>\n<p>\ud83d\udccc <strong>\u4e0b\u4e00\u6b65<\/strong>: \u5b66\u4e60 <a href=\".\/Day-20-%E9%A1%B9%E7%9B%AE2-%E8%AE%A1%E6%97%B6%E5%99%A8%E5%BA%94%E7%94%A8.md\">Day 20: \u9879\u76ee2-\u8ba1\u65f6\u5668\u5e94\u7528<\/a>\uff0c\u7ee7\u7eed\u5b9e\u6218\u9879\u76ee\u5f00\u53d1\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Day 19: \u9879\u76ee1-\u5f85\u529e\u4e8b\u9879\u5e94\u7528 \ud83c\udfaf Day 19 &#8211; \u5f85\u529e\u4e8b\u9879\u5e94\u7528 \ud83d\udcc2 \u5206\u7c7b: 09-\u9879\u76ee\u5b9e &#8230; <a title=\"Day-19-\u9879\u76ee1-\u5f85\u529e\u4e8b\u9879\u5e94\u7528\" class=\"read-more\" href=\"https:\/\/www.resilence.cn\/?p=282\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbDay-19-\u9879\u76ee1-\u5f85\u529e\u4e8b\u9879\u5e94\u7528\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-282","post","type-post","status-publish","format-standard","hentry","category-studycoding"],"_links":{"self":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282"}],"version-history":[{"count":1,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":283,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions\/283"}],"wp:attachment":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}