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

202
Views
Ejecute la función hasta que se presione el botón del mouse en JavaScript

Quiero que la función se ejecute continuamente siempre que el usuario presione el botón del mouse Pero solo se ejecuta una vez y se imprime una vez en la consola No sé cómo resolver este problema, por favor guíeme

 function handleBye() { return console.log("BYE"); } function handleHello() { return console.log("HELLO"); } <button onmousedown="handleHello()">hello</button> <button onmousedown="handleBye()">bye</button>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tal vez esté buscando setInterval y clearInterval :

 let timer; function stop() { clearInterval(timer); } function handleHello() { repeat(() => console.log("HELLO")); } function handleBye() { repeat(() => console.log("BYE")); } function repeat(what) { timer = setInterval(what, 200); // Schedule what(); // Also do it immediately }
 <button onmousedown="handleHello()" onmouseup="stop()">hello</button> <button onmousedown="handleBye()" onmouseup="stop()">bye</button>

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!