用deepseek开发一款记事日历(用deepseek搭建本地知识库)
zhezhongyun 2025-07-28 01:23 40 浏览
打开 chat.deepseek.com
输入提示词: 制作一个记事日历工具,每个月自动更新当前的月份,每天可以添加当天的备注,点击后即标记为完成
结果:
<!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;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.calendar-container {
background-color: white;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
padding: 20px;
}
.calendar-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.month-year {
font-size: 24px;
font-weight: bold;
}
.days-header {
display: grid;
grid-template-columns: repeat(7, 1fr);
text-align: center;
font-weight: bold;
margin-bottom: 10px;
}
.days-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 10px;
}
.day-cell {
min-height: 80px;
border: 1px solid #ddd;
border-radius: 5px;
padding: 5px;
position: relative;
background-color: white;
}
.day-cell.empty {
background-color: #f9f9f9;
border: none;
}
.day-number {
font-weight: bold;
margin-bottom: 5px;
}
.day-cell.today {
background-color: #e6f7ff;
border-color: #91d5ff;
}
.note-input {
width: 100%;
font-size: 12px;
border: 1px solid #eee;
border-radius: 3px;
padding: 3px;
margin-top: 5px;
}
.note {
font-size: 12px;
background-color: #f0f0f0;
border-radius: 3px;
padding: 3px;
margin-top: 3px;
word-break: break-word;
cursor: pointer;
}
.note.completed {
text-decoration: line-through;
color: #888;
background-color: #e8f5e9;
}
.nav-button {
background-color: #4CAF50;
color: white;
border: none;
padding: 8px 15px;
border-radius: 5px;
cursor: pointer;
}
.nav-button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="calendar-container">
<div class="calendar-header">
<button class="nav-button" id="prev-month">上个月</button>
<div class="month-year" id="month-year"></div>
<button class="nav-button" id="next-month">下个月</button>
</div>
<div class="days-header">
<div>日</div>
<div>一</div>
<div>二</div>
<div>三</div>
<div>四</div>
<div>五</div>
<div>六</div>
</div>
<div class="days-grid" id="days-grid"></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
let currentDate = new Date();
let currentYear = currentDate.getFullYear();
let currentMonth = currentDate.getMonth();
// 从本地存储加载笔记
let notes = JSON.parse(localStorage.getItem('calendarNotes')) || {};
// 初始化日历
renderCalendar(currentYear, currentMonth);
// 上个月按钮事件
document.getElementById('prev-month').addEventListener('click', function() {
currentMonth--;
if (currentMonth < 0) {
currentMonth = 11;
currentYear--;
}
renderCalendar(currentYear, currentMonth);
});
// 下个月按钮事件
document.getElementById('next-month').addEventListener('click', function() {
currentMonth++;
if (currentMonth > 11) {
currentMonth = 0;
currentYear++;
}
renderCalendar(currentYear, currentMonth);
});
// 渲染日历
function renderCalendar(year, month) {
const monthNames = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"];
document.getElementById('month-year').textContent = `${year}年 ${monthNames[month]}`;
const firstDay = new Date(year, month, 1);
const startingDay = firstDay.getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
const today = new Date();
let daysGrid = document.getElementById('days-grid');
daysGrid.innerHTML = '';
// 添加空白单元格
for (let i = 0; i < startingDay; i++) {
const emptyCell = document.createElement('div');
emptyCell.className = 'day-cell empty';
daysGrid.appendChild(emptyCell);
}
// 添加日期单元格
for (let day = 1; day <= daysInMonth; day++) {
const dayCell = document.createElement('div');
dayCell.className = 'day-cell';
// 如果是今天,添加特殊样式
if (year === today.getFullYear() && month === today.getMonth() && day === today.getDate()) {
dayCell.classList.add('today');
}
const dayNumber = document.createElement('div');
dayNumber.className = 'day-number';
dayNumber.textContent = day;
dayCell.appendChild(dayNumber);
// 添加笔记输入框
const noteInput = document.createElement('input');
noteInput.className = 'note-input';
noteInput.placeholder = '添加备注...';
noteInput.dataset.date = `${year}-${month}-${day}`;
noteInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter' && this.value.trim() !== '') {
const dateKey = this.dataset.date;
if (!notes[dateKey]) {
notes[dateKey] = [];
}
notes[dateKey].push({
text: this.value.trim(),
completed: false
});
localStorage.setItem('calendarNotes', JSON.stringify(notes));
renderDayNotes(dayCell, dateKey);
this.value = '';
}
});
dayCell.appendChild(noteInput);
// 渲染已有的笔记
const dateKey = `${year}-${month}-${day}`;
renderDayNotes(dayCell, dateKey);
daysGrid.appendChild(dayCell);
}
}
// 渲染某天的笔记
function renderDayNotes(dayCell, dateKey) {
// 移除现有的笔记(除了输入框)
const notesToRemove = dayCell.querySelectorAll('.note');
notesToRemove.forEach(note => note.remove());
// 添加新的笔记
if (notes[dateKey]) {
notes[dateKey].forEach((note, index) => {
const noteElement = document.createElement('div');
noteElement.className = 'note';
if (note.completed) {
noteElement.classList.add('completed');
}
noteElement.textContent = note.text;
noteElement.dataset.date = dateKey;
noteElement.dataset.index = index;
noteElement.addEventListener('click', function() {
const dateKey = this.dataset.date;
const index = parseInt(this.dataset.index);
notes[dateKey][index].completed = !notes[dateKey][index].completed;
localStorage.setItem('calendarNotes', JSON.stringify(notes));
this.classList.toggle('completed');
});
// 在输入框之前插入笔记
dayCell.insertBefore(noteElement, dayCell.querySelector('.note-input'));
});
}
}
});
</script>
</body>
</html>功能说明
- 自动显示当前月份:日历会自动显示当前月份和年份
- 导航功能:可以通过"上个月"和"下个月"按钮切换月份
- 添加备注:每天都有一个输入框,输入内容后按回车键添加备注
- 标记完成:点击备注可以标记为完成/未完成
- 数据保存:所有备注会保存在浏览器的本地存储中,刷新页面不会丢失
- 今日高亮:当前日期会有特殊背景色标记
使用方法
- 将上述代码保存为HTML文件(如calendar.html)
- 用浏览器打开该文件即可使用
- 不需要服务器支持,纯前端实现
最终效果:
相关推荐
- Python入门学习记录之一:变量_python怎么用变量
-
写这个,主要是对自己学习python知识的一个总结,也是加深自己的印象。变量(英文:variable),也叫标识符。在python中,变量的命名规则有以下三点:>变量名只能包含字母、数字和下划线...
- python变量命名规则——来自小白的总结
-
python是一个动态编译类编程语言,所以程序在运行前不需要如C语言的先行编译动作,因此也只有在程序运行过程中才能发现程序的问题。基于此,python的变量就有一定的命名规范。python作为当前热门...
- Python入门学习教程:第 2 章 变量与数据类型
-
2.1什么是变量?在编程中,变量就像一个存放数据的容器,它可以存储各种信息,并且这些信息可以被读取和修改。想象一下,变量就如同我们生活中的盒子,你可以把东西放进去,也可以随时拿出来看看,甚至可以换成...
- 绘制学术论文中的“三线表”具体指导
-
在科研过程中,大家用到最多的可能就是“三线表”。“三线表”,一般主要由三条横线构成,当然在变量名栏里也可以拆分单元格,出现更多的线。更重要的是,“三线表”也是一种数据记录规范,以“三线表”形式记录的数...
- Python基础语法知识--变量和数据类型
-
学习Python中的变量和数据类型至关重要,因为它们构成了Python编程的基石。以下是帮助您了解Python中的变量和数据类型的分步指南:1.变量:变量在Python中用于存储数据值。它们充...
- 一文搞懂 Python 中的所有标点符号
-
反引号`无任何作用。传说Python3中它被移除是因为和单引号字符'太相似。波浪号~(按位取反符号)~被称为取反或补码运算符。它放在我们想要取反的对象前面。如果放在一个整数n...
- Python变量类型和运算符_python中变量的含义
-
别再被小名词坑哭了:Python新手常犯的那些隐蔽错误,我用同事的真实bug拆给你看我记得有一次和同事张姐一起追查一个看似随机崩溃的脚本,最后发现罪魁祸首竟然是她把变量命名成了list。说实话...
- 从零开始:深入剖析 Spring Boot3 中配置文件的加载顺序
-
在当今的互联网软件开发领域,SpringBoot无疑是最为热门和广泛应用的框架之一。它以其强大的功能、便捷的开发体验,极大地提升了开发效率,成为众多开发者构建Web应用程序的首选。而在Spr...
- Python中下划线 ‘_’ 的用法,你知道几种
-
Python中下划线()是一个有特殊含义和用途的符号,它可以用来表示以下几种情况:1在解释器中,下划线(_)表示上一个表达式的值,可以用来进行快速计算或测试。例如:>>>2+...
- 解锁Shell编程:变量_shell $变量
-
引言:开启Shell编程大门Shell作为用户与Linux内核之间的桥梁,为我们提供了强大的命令行交互方式。它不仅能执行简单的文件操作、进程管理,还能通过编写脚本实现复杂的自动化任务。无论是...
- 一文学会Python的变量命名规则!_python的变量命名有哪些要求
-
目录1.变量的命名原则3.内置函数尽量不要做变量4.删除变量和垃圾回收机制5.结语1.变量的命名原则①由英文字母、_(下划线)、或中文开头②变量名称只能由英文字母、数字、下画线或中文字所组成。③英文字...
- 更可靠的Rust-语法篇-区分语句/表达式,略览if/loop/while/for
-
src/main.rs://函数定义fnadd(a:i32,b:i32)->i32{a+b//末尾表达式}fnmain(){leta:i3...
- C++第五课:变量的命名规则_c++中变量的命名规则
-
变量的命名不是想怎么起就怎么起的,而是有一套固定的规则的。具体规则:1.名字要合法:变量名必须是由字母、数字或下划线组成。例如:a,a1,a_1。2.开头不能是数字。例如:可以a1,但不能起1a。3....
- Rust编程-核心篇-不安全编程_rust安全性
-
Unsafe的必要性Rust的所有权系统和类型系统为我们提供了强大的安全保障,但在某些情况下,我们需要突破这些限制来:与C代码交互实现底层系统编程优化性能关键代码实现某些编译器无法验证的安全操作Rus...
- 探秘 Python 内存管理:背后的神奇机制
-
在编程的世界里,内存管理就如同幕后的精密操控者,确保程序的高效运行。Python作为一种广泛使用的编程语言,其内存管理机制既巧妙又复杂,为开发者们提供了便利的同时,也展现了强大的底层控制能力。一、P...
- 一周热门
- 最近发表
- 标签列表
-
- HTML 教程 (33)
- HTML 简介 (35)
- HTML 实例/测验 (32)
- HTML 测验 (32)
- JavaScript 和 HTML DOM 参考手册 (32)
- HTML 拓展阅读 (30)
- HTML文本框样式 (31)
- HTML滚动条样式 (34)
- HTML5 浏览器支持 (33)
- HTML5 新元素 (33)
- HTML5 WebSocket (30)
- HTML5 代码规范 (32)
- HTML5 标签 (717)
- HTML5 标签 (已废弃) (75)
- HTML5电子书 (32)
- HTML5开发工具 (34)
- HTML5小游戏源码 (34)
- HTML5模板下载 (30)
- HTTP 状态消息 (33)
- HTTP 方法:GET 对比 POST (33)
- 键盘快捷键 (35)
- 标签 (226)
- opacity 属性 (32)
- transition 属性 (33)
- 1-1. 变量声明 (31)
