You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
996 B
34 lines
996 B
let todoarray = JSON.parse(localStorage.getItem("todos")) || [];
|
|
|
|
function additem() {
|
|
let text = document.getElementById("todoitem").value;
|
|
// jestli text je prázdný tak ukončí celou funkci
|
|
if (text.trim() == "" ) {return;}
|
|
todoarray.push(text);
|
|
console.log(todoarray);
|
|
savetodos();
|
|
renderlist();
|
|
document.getElementById("todoitem").value = "";
|
|
}
|
|
function createlist(value, index){
|
|
i = index+1
|
|
document.getElementById("todolist")
|
|
.innerHTML += '<li class="todolistitem">'+i+". "+value
|
|
+'<button class="btn btn-danger mx-2 my-1 " onclick="removeitem('+index+')">Smazat</button></li>';
|
|
}
|
|
function removeitem(index) {
|
|
todoarray.splice(index,1);
|
|
savetodos();
|
|
renderlist();
|
|
}
|
|
function renderlist(){
|
|
document.getElementById("todolist").innerHTML = "";
|
|
todoarray.forEach(createlist);
|
|
}
|
|
|
|
function savetodos(){
|
|
console.log(JSON.stringify(todoarray));
|
|
localStorage.setItem("todos",JSON.stringify(todoarray));
|
|
}
|
|
|
|
renderlist();
|