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

192
Views
Cómo verificar si pasó el tiempo (temporizador)

tengo codigo:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get the Value of Text Input Field in JavaScript</title> </head> <body> <input type="number" placeholder="Type something..." id="myInput"> <button type="button" onclick="getInputValue();">Get Value</button> <script> function getInputValue(){ // Selecting the input element and get its value // var inputVal = document.getElementById("myInput").value; var d = new Date(); var n = d.getTime(); var number = (document.getElementById("myInput").value); number=parseInt(number); var inputVal= number+n; alert(inputVal); } </script> </body> </html>

En el código estoy revisando la hora actual en milisegundos y en el formulario escribo el tiempo en ms y sumo el tiempo actual con el tiempo en el formulario y por ejemplo quiero agregar a la hora actual 6000 ms y antes de que pasen estos 6000 ms quiero pasar por ejemplo, a la información del sitio web "ON" y luego "OFF". ¿Debo usar aquí el ciclo para verificar si pasó este tiempo o puedo hacerlo de otra manera?

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

0

usando la API requestAnimationFrame para hacer una recursión

temporizador de demostración de codepen

about 4 years ago · Juan Pablo Isaza Report

0

Avíseme si algo no está claro ( realmente no sé qué podría ser complicado aquí )

Excepto por +val , esto es en lugar de parseInt(val)

Excepto2 para | 0 , esto es en lugar de toFixed()

 $('#info').hide(); const getInputValue = ()=>{ const val = $('#myInput').val(); $('#info').fadeIn(); console.log(`info here for ~${(+val / 1000) | 0} sec`); setTimeout(()=>{ $('#info').fadeOut(); }, +val); };
 *{padding:10px}
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="number" value="2000" placeholder="Type something..." id="myInput" /> <button type="button" onclick="getInputValue();">Show Info</button> <div id="info">Website information "ON"</div>

JQuery no es necesario 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!