-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
53 lines (41 loc) · 1.55 KB
/
main.js
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
// main.js
window.onload = function () {
displayNoteBoxes();
document.getElementById('createNoteBtn').addEventListener('click', function () {
window.location.href = 'http://127.0.0.1:5500/write.html';
});
};
function displayNoteBoxes() {
var noteBoxesContainer = document.getElementById('noteBoxes');
noteBoxesContainer.innerHTML = '';
var notes = JSON.parse(localStorage.getItem('notes')) || [];
notes.forEach(function (note) {
var noteBox = document.createElement('div');
noteBox.className = 'note-box';
var titleElement = document.createElement('h2');
titleElement.textContent = note.title;
var contentElement = document.createElement('p');
contentElement.textContent = note.content;
noteBox.appendChild(titleElement);
noteBox.appendChild(contentElement);
noteBoxesContainer.appendChild(noteBox);
});
}
function doneClicked() {
var title = document.getElementById('titleInput').value;
var content = document.getElementById('contentInput').value;
if (title.trim() !== '' && content.trim() !== '') {
var notes = JSON.parse(localStorage.getItem('notes')) || [];
var note = {
title: title,
content: content
};
notes.push(note);
localStorage.setItem('notes', JSON.stringify(notes));
document.getElementById('titleInput').value = '';
document.getElementById('contentInput').value = '';
displayNoteBoxes();
} else {
alert('Please enter both title and content.');
}
}