|
| 1 | +let notes = []; |
| 2 | + |
| 3 | +function showNotes() { |
| 4 | + const noteList = document.getElementById('noteList'); |
| 5 | + noteList.innerHTML = '<h3>Notes</h3>'; |
| 6 | + |
| 7 | + for (let i = 0; i < notes.length; i++) { |
| 8 | + const noteItem = document.createElement('div'); |
| 9 | + noteItem.classList.add('note-item'); |
| 10 | + noteItem.innerHTML = ` |
| 11 | + <p><a href="#" onclick="showNoteDetails(${i})">${notes[i].title}</a></p> |
| 12 | + <button onclick="deleteNote(${i})">Delete</button> |
| 13 | + `; |
| 14 | + noteList.appendChild(noteItem); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +function showNoteDetails(index) { |
| 19 | + const noteDetails = document.getElementById('noteDetails'); |
| 20 | + const selectedNote = notes[index]; |
| 21 | + |
| 22 | + if (selectedNote) { |
| 23 | + noteDetails.innerHTML = ` |
| 24 | + <h3>${selectedNote.title}</h3> |
| 25 | + <p>${selectedNote.content}</p> |
| 26 | + `; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +function showAddNoteForm() { |
| 31 | + const addNoteForm = document.getElementById('addNoteForm'); |
| 32 | + addNoteForm.style.display = 'block'; |
| 33 | +} |
| 34 | + |
| 35 | +function addNote() { |
| 36 | + const noteTitle = document.getElementById('noteTitle').value; |
| 37 | + const noteContent = document.getElementById('noteContent').value; |
| 38 | + |
| 39 | + if (noteTitle && noteContent) { |
| 40 | + notes.push({ title: noteTitle, content: noteContent }); |
| 41 | + showNotes(); |
| 42 | + resetAddNoteForm(); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function resetAddNoteForm() { |
| 47 | + document.getElementById('noteTitle').value = ''; |
| 48 | + document.getElementById('noteContent').value = ''; |
| 49 | + document.getElementById('addNoteForm').style.display = 'none'; |
| 50 | +} |
| 51 | + |
| 52 | +function deleteNote(index) { |
| 53 | + notes.splice(index, 1); |
| 54 | + showNotes(); |
| 55 | +} |
| 56 | + |
| 57 | +showNotes(); |
0 commit comments