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

124
Views
Me gustaría agregar límites numéricos a este bloque de código.
document.querySelectorAll('input').forEach(input => { input.addEventListener("keydown", function(e) { var charValue = String.fromCharCode(e.keyCode); if (((!/^(\d+)?([.]?\d{0,1})?$/.test(this.value + e.key)) && (e.which != 8))) { e.preventDefault() } }) }) SetPoint :<input id="input" type="text" name="setPoint" max="5" min="1" />

este bloque de código está un poco más allá de mi comprensión, pero supongo que usa e.something y <= en la declaración if para agregar un menor o igual para limitar el número que aceptará el formulario

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cada vez que escribe una letra en el teclado, obtiene un e.keyCode o e.key específico. Intente depurar el valor de cada variable para comprender el código.

Para poner un límite, simplemente haga una verificación para evitar el comportamiento predeterminado (evitar que se escriba más)

 var nextValue = this.value + e.key; if (nextValue < 1 || nextValue > 5) { e.preventDefault() }
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!