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

254
Views
Haga que un botón se deshabilite al hacer clic, pero habilítelo hasta que la cuenta regresiva no sea cero
function counter2(){ var counter =10; var on=document.getElementById("bet"); setInterval(function(){ counter--; if(counter==9){ on.innerHTML = ""; } if(counter>=0){ id=document.getElementById("res"); var bet=document.getElementById("pts"); var beth=document.getElementById("beth"); var betv=document.getElementById("betv"); id.innerHTML="Bet within " +counter + " seconds";; beth.disabled = false; //Beth is both Function and button // beth.style.backgroundColor = "#4CAF50"; betv.disabled = false; betv.style.backgroundColor = "#008CBA"; beth.style.cursor = 'pointer'; betv.style.cursor = 'pointer'; } if(counter==0){ counter1(); } }, 1000); }

Estoy creando una función en la que se deshabilitará un botón después de hacer clic, pero el contador anterior habilita automáticamente los botones, pero quiero que ambos se ejecuten i. E. Deshabilitar un botón después de hacer clic y también deshabilitar si el temporizador está funcionando y también habilitar los botones si no se hace clic en el botón

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

0

 document.addEventListener('DOMContentLoaded', () => { const myButton = document.getElementById('my-button'); const status = document.getElementById('status'); let counter = 10; let timerHandle; myButton.addEventListener('click', () => { status.innerText = `Button will enable in ${counter} seconds`; myButton.disabled = true; timerHandle = setInterval(() => { counter--; status.innerText = `Button will enable in ${counter} seconds`; if (counter === 0) { clearInterval(timerHandle); status.innerText = `Timer cleared.`; myButton.disabled = false; } }, 1000); }); });
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> p { color: red; } </style> </head> <body> <div> <p id="status"></p> </div> <div> <button id="my-button">Button</button> </div> <script src="script.js"></script> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

Podrías usar:

 var elem = document.getElementById('button'); elem.addEventListener('click',buttonClicked); function buttonClicked(){ //do stuff console.log("clicked") elem.disabled = true; setTimeout(() => {elem.disabled =false}, 500); }
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!