Невозможно сохранить заметки в localStorage с помощью JS.Javascript

Форум по Javascript
Ответить
Anonymous
 Невозможно сохранить заметки в localStorage с помощью JS.

Сообщение Anonymous »

Я пытался сохранить заметки в локальном хранилище разными способами, но, что бы я ни пробовал, ничего не работает должным образом. Я изучил несколько подходов и попробовал разные методы, но ни один из них не дал мне тех результатов, на которые я надеялся. Я также решил обратиться за помощью к ИИ, чтобы посмотреть, сможет ли он мне помочь. К сожалению, хотя он и предоставил некоторые предложения, решения не решили проблему. Я дошел до того, что все еще пытаюсь разобраться в этом и действительно нуждаюсь в четком, простом и пошаговом руководстве, чтобы решить эту проблему раз и навсегда.
let note_list=document.getElementById("note_list_container")

function addNote(){
let input_note=document.getElementById("note").value
if(input_note){

let copyButton=document.createElement("button")
copyButton.className="copy_button"
copyButton.innerHTML=``
copyButton.onclick=function copyContent(){
navigator.clipboard.writeText(input_note) //creating copy paste button !
}

let deleteButton=document.createElement("button")
deleteButton.className="delete_button"
deleteButton.innerHTML=``
deleteButton.onclick=function deleteNote(){
display_note.style.display="none" //creating delete note button, the delete button is created further down the page but its still working !
}

let editButton=document.createElement("button")
editButton.innerHTML="edit"

let display_note=document.createElement("p")

display_note.className="note_info" //appeding each button to our note
display_note.textContent=input_note
note_list.appendChild(display_note)
display_note.appendChild(deleteButton)
display_note.appendChild(copyButton)
document.getElementById("note").value=""
display_note.appendChild(editButton);

//creating a variable that will hold the localstorage
//checks if there are any notes saved, if not it generates the localstorage

let notes=localStorage.getItem("notes") ? JSON.parse(localStorage.getItem("notes")) : []
notes.push(note_list.innerHTML)
localStorage.setItem("notes", JSON.stringify(notes))
console.log(localStorage.getItem("notes"))
//creating the logic for the edit //tried this but doesnt seem to work

editButton.onclick=function(){ //logic for editing the note and than saving the change
let edit_form=document.createElement("input")
edit_form.value=display_note.textContent
edit_form.type="text"
let save=document.createElement("button")
save.textContent="save"
save.onclick=function(){
display_note.textContent=edit_form.value
display_note.appendChild(deleteButton)
display_note.appendChild(copyButton)
display_note.appendChild(editButton)
}
display_note.innerHTML="" //emptying the html of the form so only the edit form and the save button appears
display_note.appendChild(edit_form)
display_note.appendChild(save)

}

}

}



Подробнее здесь: https://stackoverflow.com/questions/793 ... e-using-js
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»