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

113
Views
¿Cómo obligo al campo de entrada a ingresar números solo en el rango 1 - 12?

Estoy tratando de agregar un evento keyup en mi elemento de entrada creado dinámicamente.

El evento keyup no funciona cuando ejecuto el código. ¿Dónde me he equivocado?

 for(var j = 1; j < table.rows.length; j++){ if(table.rows[j].cells.item(10).innerHTML != 0 && table.rows[j].cells.item(10).innerHTML != null){ var row = t1.insertRow(t1.rows.length); var cell = row.insertCell(0); var cell1 = row.insertCell(1); var cell2 = row.insertCell(2); cell.innerText = table.rows[j].cells.item(2).innerText; var formatter = new Intl.NumberFormat('en-IN', { style: 'currency', currency: 'INR', }); cell1.innerText = formatter.format(table.rows[j].cells.item(10).innerText); var input=document.createElement("input"); input.style.textAlign="center"; input.className="installments"; input.type="number"; input.placeholder = "range (1-12)" $(function() { $('.installments').keyup(function() { const inputVal = parseInt($(this).val()); console.log(inputVal); //shows nothing as I give input if (inputVal <= 0 || inputVal > 12 || parseString(inputVal).includes('.')){ $(this).val()=""; alert("Installments should be within 1-12 months range and should be a whole number"); } }); }); input.style.width="10em"; cell2.appendChild(input); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En primer lugar, elimine el detector de eventos keyup y el acceso directo para $(document).ready() fuera del bucle. Básicamente, está creando el detector de eventos en cada iteración del bucle for (anidado).

Luego, cuando mueva el detector de eventos fuera del ciclo, use la delegación de eventos para apuntar a los nodos que se agregarán en el futuro. Por ejemplo $(document).on('keyup', '.installments', event => {}) .

Para obtener más información sobre la delegación de eventos en jQuery, consulte aquí

about 4 years ago · Juan Pablo Isaza Report
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!