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
La función de rebote se activa inmediatamente al activar la tecla; en su lugar, debe activarse después de un segundo

Estoy tratando de implementar una función de rebote personalizada que debe alertar cualquier dato que el usuario haya ingresado en un cuadro de texto después de un segundo de retraso (después de que el usuario haya dejado de escribir). ¿Qué estoy haciendo mal? Activa la alerta () inmediatamente con un solo carácter.

 function debounce(func, timeout) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, args); }, timeout); }; } function saveInput(args) { alert(args); //This triggers immediately } const processChange = (event) => { debounce(saveInput(event.target.value), 1000); }
 <input type="text" onkeyup="processChange(event)" />

¿Pueden sugerir si me pierdo algo aquí?

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

0

Esto ha funcionado para mí. Sin embargo, myInput es una variable global aquí.

 function debounce(callback, delay) { let timeout; return function () { clearTimeout(timeout); timeout = setTimeout(callback, delay); } } const myInput = document.getElementById("myInput"); function helloInput() { alert(myInput.value); } myInput.addEventListener( "keyup", debounce(helloInput, 1000) ); myInput.focus();
 <input type="text" id="myInput" />

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!