-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path小记.html
More file actions
123 lines (116 loc) · 3.31 KB
/
Copy path小记.html
File metadata and controls
123 lines (116 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>小记</title>
<style>
/* CSS样式 */
body {
font-family: Arial, sans-serif;
margin: 30px;
}
h1 {
text-align: center;
}
p {
margin-bottom: 10px;
}
textarea {
width: 100%;
height: 100px;
padding: 5px;
border-radius: 5px;
border: 1px solid #ccc;
}
button {
padding: 8px 16px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
.noteItem {
margin-bottom: 10px;
padding: 10px;
background-color: #f2f2f2;
border-radius: 5px;
}
.noteItem p {
margin: 0;
}
.noteItem button {
float: right;
background-color: #f44336;
}
.noteItem button:hover {
background-color: #d32f2f;
}
</style>
</head>
<body>
<h1>小记</h1>
<p>输入笔记内容(长按选择内容可以分享):</p>
<textarea id="noteInput"></textarea>
<br><br>
<button id="addNoteBtn">添加笔记</button>
<br><br>
<ul id="notesList"></ul>
<script>
// JavaScript代码
const noteInput = document.getElementById('noteInput');
const addNoteBtn = document.getElementById('addNoteBtn');
const notesList = document.getElementById('notesList');
let notes = [];
// 加载笔记数据
function loadNotes() {
const notesStr = localStorage.getItem('notes');
if (notesStr) {
notes = JSON.parse(notesStr);
for (const note of notes) {
addNoteToList(note);
}
}
}
// 保存笔记数据
function saveNotes() {
localStorage.setItem('notes', JSON.stringify(notes));
}
// 添加笔记到列表中
function addNoteToList(note) {
const noteItem = document.createElement('li');
noteItem.className = 'noteItem';
noteItem.innerHTML = `
<p>${note}</p>
<button>删除</button>
`;
noteItem.querySelector('button').addEventListener('click', function() {
notesList.removeChild(noteItem);
notes.splice(notes.indexOf(note), 1);
saveNotes();
});
notesList.appendChild(noteItem);
}
// 监听按钮点击事件
addNoteBtn.addEventListener('click', function() {
const note = noteInput.value.trim();
if (note) {
notes.push(note);
addNoteToList(note);
saveNotes();
noteInput.value = '';
}
});
// 初始化应用
loadNotes();
</script>
</body>
</html>