Всем привет! Я сделал вставку элемента с помощью JavaScript. Попробуйте код ниже: (Заполните ввод и нажмите Enter, чтобы добавить элемент)
Это происходит с этим волшебным кодом JavaScript:
const mainInput = document.getElementById('main-input') const itemList = document.getElementById('item-list') mainInput.addEventListener('keydown', (ev) => { if (ev.key === "Enter") { ev.preventDefault() if (mainInput.value !== "") { const newItem = document.createElement('p') newItem.classList.add('item') itemList.appendChild(newItem) newItem.innerText = mainInput.value mainInput.value = "" } } })
Оригинал: “https://dev.to/mrhabibi/item-insertion-on-enter-key-4l89”