grok-3-preview-02-24· xAI LMArena Human Preference 140K
做一个笔记本html
- User
做一个笔记本html
- Assistant
下面是一个简单的笔记本风格的HTML页面示例,包含基本的笔记功能(添加、编辑、删除笔记),并使用CSS进行美化。你可以直接复制代码到本地运行,或者根据需要进行修改。
<!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> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } .container { max-width: 800px; margin: 0 auto; background-color: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px; } h1 { text-align: center; color: #333; } .note-input { margin-bottom: 20px; } .note-input textarea { width: 100%; height: 100px; padding: 10px; font-size: 16px; border: 1px solid #ddd; border-radius: 4px; resize: vertical; } .note-input button { padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } .note-input button:hover { background-color: #218838; } .note-list { list-style: none; padding: 0; } .note-item { background-color: #f9f9f9; padding: 15px; margin-bottom: 10px; border-radius: 4px; display: flex; justify-content: space-between; align-items: center; } .note-item p { margin: 0; flex-grow: 1; padding-right: 10px; } .note-item button { padding: 5px 10px; margin-left: 5px; border: none; border-radius: 4px; cursor: pointer; } .note-item .edit-btn { background-color: #007bff; color: white; } .note-item .edit-btn:hover { background-color: #0056b3; } .note-item .delete-btn { background-color: #dc3545; color: white; } .note-item .delete-btn:hover { background-color: #c82333; } </style> </head> <body> <div class="container"> <h1>我的笔记本</h1> <div class="note-input"> <textarea id="noteText" placeholder="输入你的笔记..."></textarea> <button onclick="addNote()">添加笔记</button> </div> <ul class="note-list" id="noteList"></ul> </div> <script> let notes = []; let editIndex = -1; // 添加或编辑笔记 function addNote() { const noteText = document.getElementById('noteText').value.trim(); if (noteText === '') { alert('笔记内容不能为空!'); return; } if (editIndex === -1) { // 添加新笔记 notes.push(noteText); } else { // 编辑已有笔记 notes[editIndex] = noteText; editIndex = -1; } document.getElementById('noteText').value = ''; renderNotes(); } // 删除笔记 function deleteNote(index) { notes.splice(index, 1); renderNotes(); } // 编辑笔记 function editNote(index) { document.getElementById('noteText').value = notes[index]; editIndex = index; } // 渲染笔记列表 function renderNotes() { const noteList = document.getElementById('noteList'); noteList.innerHTML = ''; notes.forEach((note, index) => { const li = document.createElement('li'); li.className = 'note-item'; li.innerHTML = ` <p>${note}</p> <div> <button class="edit-btn" onclick="editNote(${index})">编辑</button> <button class="delete-btn" onclick="deleteNote(${index})">删除</button> </div> `; noteList.appendChild(li); }); } </script> </body> </html>功能说明:
- 添加笔记:在文本框中输入内容,点击“添加笔记”按钮即可添加一条新笔记。
- 编辑笔记:点击笔记右侧的“编辑”按钮,将笔记内容加载到文本框中,修改后再次点击“添加笔记”保存。
- 删除笔记:点击笔记右侧的“删除”按钮即可删除该条笔记。
- 样式美化:页面采用简洁的笔记本风格,包含阴影、圆角、按钮悬停效果等。
使用方法:
- 将上述代码保存为一个
.html文件(例如notebook.html)。 - 使用浏览器打开该文件,即可看到一个简单的笔记本页面。
- 输入笔记内容,点击“添加笔记”按钮,笔记会显示在下方列表中。
注意事项:
- 当前笔记数据仅保存在浏览器内存中,刷新页面后数据会丢失。如果需要持久化存储,可以结合
localStorage或后端数据库。 - 你可以根据需要进一步调整样式(CSS)或添加更多功能(例如分类、搜索等)。
如果你需要更复杂的功能或样式调整,请告诉我,我可以帮你进一步完善!
- User
给我完整html
- Assistant
以下是一个更完整的笔记本HTML页面,增加了以下功能和改进:
- 使用
localStorage实现笔记的持久化存储,刷新页面后数据不会丢失。 - 添加了笔记的时间戳,显示每条笔记的创建或修改时间。
- 增加了简单的搜索功能,可以根据关键词过滤笔记。
- 优化了样式,使页面更美观且适配移动端。
- 添加了简单的分类功能(可选)。
你可以直接复制以下代码保存为
.html文件并在浏览器中运行。<!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> * { box-sizing: border-box; } body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } .container { max-width: 800px; margin: 0 auto; background-color: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px; } h1 { text-align: center; color: #333; } .note-input { margin-bottom: 20px; } .note-input textarea { width: 100%; height: 100px; padding: 10px; font-size: 16px; border: 1px solid #ddd; border-radius: 4px; resize: vertical; } .note-input select { padding: 5px; font-size: 16px; margin-top: 10px; border-radius: 4px; } .note-input button { padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; margin-top: 10px; } .note-input button:hover { background-color: #218838; } .search-bar { margin-bottom: 20px; } .search-bar input { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ddd; border-radius: 4px; } .note-list { list-style: none; padding: 0; } .note-item { background-color: #f9f9f9; padding: 15px; margin-bottom: 10px; border-radius: 4px; display: flex; justify-content: space-between; align-items: flex-start; } .note-item .note-content { flex-grow: 1; padding-right: 10px; } .note-item .note-content p { margin: 0; word-wrap: break-word; } .note-item .note-meta { font-size: 12px; color: #888; margin-top: 5px; } .note-item .note-actions { display: flex; gap: 5px; } .note-item button { padding: 5px 10px; border: none; border-radius: 4px; cursor: pointer; } .note-item .edit-btn { background-color: #007bff; color: white; } .note-item .edit-btn:hover { background-color: #0056b3; } .note-item .delete-btn { background-color: #dc3545; color: white; } .note-item .delete-btn:hover { background-color: #c82333; } @media (max-width: 600px) { .note-item { flex-direction: column; align-items: stretch; } .note-item .note-actions { margin-top: 10px; justify-content: flex-end; } } </style> </head> <body> <div class="container"> <h1>我的笔记本</h1> <div class="note-input"> <textarea id="noteText" placeholder="输入你的笔记..."></textarea> <select id="noteCategory"> <option value="个人">个人</option> <option value="工作">工作</option> <option value="学习">学习</option> <option value="其他">其他</option> </select> <button onclick="addNote()">添加笔记</button> </div> <div class="search-bar"> <input type="text" id="searchInput" placeholder="搜索笔记..." oninput="searchNotes()"> </div> <ul class="note-list" id="noteList"></ul> </div> <script> let notes = JSON.parse(localStorage.getItem('notes')) || []; let editIndex = -1; // 初始化时渲染笔记 window.onload = function() { renderNotes(); }; // 添加或编辑笔记 function addNote() { const noteText = document.getElementById('noteText').value.trim(); const noteCategory = document.getElementById('noteCategory').value; if (noteText === '') { alert('笔记内容不能为空!'); return; } const note = { text: noteText, category: noteCategory, timestamp: new Date().toLocaleString() }; if (editIndex === -1) { // 添加新笔记 notes.push(note); } else { // 编辑已有笔记 note.timestamp = new Date().toLocaleString(); // 更新时间戳 notes[editIndex] = note; editIndex = -1; } document.getElementById('noteText').value = ''; saveNotes(); renderNotes(); } // 删除笔记 function deleteNote(index) { notes.splice(index, 1); saveNotes(); renderNotes(); } // 编辑笔记 function editNote(index) { const note = notes[index]; document.getElementById('noteText').value = note.text; document.getElementById('noteCategory').value = note.category; editIndex = index; } // 搜索笔记 function searchNotes() { const searchText = document.getElementById('searchInput').value.toLowerCase(); renderNotes(searchText); } // 渲染笔记列表 function renderNotes(searchText = '') { const noteList = document.getElementById('noteList'); noteList.innerHTML = ''; const filteredNotes = notes.filter(note => note.text.toLowerCase().includes(searchText) || note.category.toLowerCase().includes(searchText) ); filteredNotes.forEach((note, index) => { const li = document.createElement('li'); li.className = 'note-item'; li.innerHTML = ` <div class="note-content"> <p>${note.text}</p> <div class="note-meta"> 分类: ${note.category} | 时间: ${note.timestamp} </div> </div> <div class="note-actions"> <button class="edit-btn" onclick="editNote(${index})">编辑</button> <button class="delete-btn" onclick="deleteNote(${index})">删除</button> </div> `; noteList.appendChild(li); }); } // 保存笔记到 localStorage function saveNotes() { localStorage.setItem('notes', JSON.stringify(notes)); } </script> </body> </html>功能说明:
- 笔记持久化:使用
localStorage存储笔记数据,刷新页面后数据不会丢失。 - 时间戳:每条笔记会显示创建或修改的时间。
- 分类功能:可以为笔记选择分类(个人、工作、学习、其他)。
- 搜索功能:通过搜索框可以根据笔记内容或分类进行过滤。
- 响应式设计:页面适配移动端,笔记在小屏幕上会垂直排列。
- 美观样式:优化了按钮、输入框、笔记列表的样式,增加了阴影、圆角等效果。
使用方法:
- 将上述代码保存为一个
.html文件(例如notebook.html)。 - 使用浏览器打开该文件,即可看到一个功能完整的笔记本页面。
- 输入笔记内容,选择分类,点击“添加笔记”按钮,笔记会显示在下方列表中。
- 使用搜索框可以快速查找笔记。
- 点击“编辑”或“删除”按钮可以修改或删除笔记。
注意事项:
- 笔记数据存储在浏览器的
localStorage中,仅限当前设备和浏览器。如果需要跨设备同步,可以结合后端服务器和数据库。 - 你可以根据需要调整样式(CSS)或添加更多功能(例如导出笔记、提醒功能等)。
如果你需要进一步的功能扩展或样式调整,请告诉我,我会继续帮你完善!
- 使用
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.