在
重繪 倒計時之前沒有出現并且它被禁用
當我重繪 頁面時,我的倒計時計時器作業正常,但是當我只重繪 特定的 div 時,我的倒計時不會顯示并且按鈕被禁用。
注意:我disabled使用標簽禁用了我的按鈕
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");
}
}());
這是我的 html 代碼,當我重繪 整個頁面時它可以正常作業但是當我重繪 #container3我的按鈕被禁用并且倒計時沒有顯示
<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>
uj5u.com熱心網友回復:
我認為這是解決方案,但我不確定我是否正確理解您要執行的操作:
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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/410729.html
標籤:
