Вот мой JS:
Код: Выделить всё
let todos = [];
const addNewBtn = document.getElementById("addNewBtn");
function addNew(){
const existingInput = document.getElementById("inputTodo");
if (existingInput) return;
const input = document.createElement("input");
input.type = "text";
input.id = "inputTodo";
input.placeholder = "Enter to do";
input.style.display = "block"
addNewBtn.insertAdjacentElement("afterend", input)
input.focus();
document.addEventListener("keydown", event => {
if(event.key === "Enter"){
event.preventDefault();
if(input && document.activeElement === input){
saveTodo();
}
}
})
input.addEventListener("blur", () => {
setTimeout(saveTodo, 0);
});
function saveTodo(){
const value = input.value.trim();
if(value !== ""){
todos.push({ id: Date.now(), text: value, completed: false });
renderTodos();
}
input.remove();
}
}
function renderTodos(){
console.clear();
for(const todo of todos){
console.log(todo.text);
}
}
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/798 ... st-website
Мобильная версия