antes de
después de actualizar la cuenta regresiva no apareció y se deshabilita
cuando actualizo la página, mi temporizador de cuenta regresiva funciona perfectamente, pero cuando actualizo solo un div particular, mi cuenta regresiva no aparece y el botón se desactiva.
nota: utilicé la etiqueta disabled para deshabilitar mi botón
function refreshDiv() { $('#container3').load(window.location.href + " #container3 >"); }JavaScript
var spn = document.getElementById("count"); var btn = document.getElementById("btnCounter"); var count = 2; // Set count var timer = null; // For referencing the timer (function countDown() { // Display counter and start counting down spn.textContent = count; // Run the function again every second if the count is not zero if (count !== 0) { timer = setTimeout(countDown, 1000); count--; // decrease the timer } else { // Enable the button btn.removeAttribute("disabled"); } }()); este es mi código html, funciona correctamente cuando actualizo toda la página, pero cuando actualizo #container3 mi botón se deshabilitó y la cuenta regresiva no se mostró
<div class="container2" id="container3"> <h4 id="title">here</h4> <div class="controls"> <div class="main-controls"> <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" id="btnCounter" disabled > File <span id="count"></span> </button> <div class="dropdown-menu"> <button id="txt-btn" class="dropdown-item" onclick="refreshDiv();"> Save here </button>Creo que esta es la solución, pero no estoy seguro de entender correctamente lo que estás tratando de hacer:
var spn = document.getElementById("count"); var btn = document.getElementById("btnCounter"); var count = 2; // Set count var timer = null; // For referencing the timer (function countDown() { // Display counter and start counting down spn.textContent = count; // Run the function again every second if the count is not zero if (count !== 0) { timer = setTimeout(countDown, 1000); count--; // decrease the timer } else { // Enable the button btn.removeAttribute("disabled"); } }()); function refreshDiv() { location.reload(); } this is my html code its work properly when I refresh the whole page but when I refresh #container3 my button got disabled and countdown didn't showed <div class="container2" id="container3"> <h4 id="title">Title</h4> <div class="controls"> <div class="main-controls"> <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" id="btnCounter" disabled> File <span id="count"></span> </button> <div class="dropdown-menu"> <button id="txt-btn" class="dropdown-item" onclick="refreshDiv();">Save</button> </div> </div> </div> </div> </div>