enter image description here I am new in code. Please help. i am saving inputs to local storage. I input several todo list like sleep, shopping, study, joggingAss you see on picture, there are 2 sleep. You can see in picture. I would like ti write alert when i input the same todo. like not to input sleep or shopping twice.
const newtodo = document.querySelector("#todo") const form = document.querySelector("#todo-form"); form.addEventListener("submit", addtodoToLocalStorage); function addtodoToLocalStorage(e) { const value = newtodo.value; let todos; if (localStorage.getItem("input") === null) { todos = []; } else { todos = JSON.parse(localStorage.getItem("input")) } todos.push(value); localStorage.setItem("input", JSON.stringify(todos)) newtodo.value = ""; e.preventDefault(); }
https://stackoverflow.com/questions/65546260/i-would-like-not-to-add-the-same-value-to-local-storage-javascript January 03, 2021 at 11:00AM
没有评论:
发表评论