Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Haga clic en para agregar texto de entrada de línea claro - javascript

Lucho con el problema de borrar el campo de entrada de texto cuando se agrega una nueva línea al hacer clic en el botón. Cuando agrego un número al campo de entrada y hago clic en el botón +, quiero que el número agregado en la primera línea permanezca en el campo de entrada, pero en su lugar se borra. La solución es quizás muy fácil, pero como estoy aprendiendo javascript en este momento, no puedo encontrar la razón por la cual el campo eliminó mis entradas. Aquí está mi código:

 function Item(data) { Object.assign(this, data) this.getItemHtml = function () { const {itemNo, quantity} = this; return ` <ul class="grid list-item"> <li class="col-1">${this.itemNo++}</li> <li class="col-2"><input type="number" id="item-qty${itemNo}" required></li> </ul> `; }} const itemNo = new Item(iItem.itemData) function render() { document.getElementById("i-list").innerHTML += itemNo.getItemHtml() } function addItem() { render() getInput() updateHtmlValue() } document.getElementById("add-item").addEventListener("click", addItem) function getInput() { var el = document.querySelector("ul li:nth-child(2) input") if (el) { el.addEventListener("change", function (event) { let inputValue = event.target.value; if (inputValue < 0) { inputValue = 0 } localStorage.setItem("inputValue", inputValue) }) } } function updateHtmlValue() { var input = localStorage.getItem("inputValue") }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!