【发布时间】:2022-01-04 08:12:00
【问题描述】:
我的container div 中有countdown,但是当我尝试重新加载特定的container 时,它的重新加载完美但我的countdown 没有出现,而且按钮也被禁用..
function refreshDiv() {
$('.container').load(window.location.href + " .container >*");
}
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
<div class="container">
<h2>choose product </h2>
<input type="file" name="inpFile" id="inpFile">
<div class="image-preview" id="imagePreview">
<img src="" alt="Image Preview" id="zoom" class="image-
preview__image">
<span class="image-preview__default-text">choose image</span>
</div>
</div>
<div class="container2">
<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</button>
【问题讨论】:
-
@Andreas 我是新来的
-
如果您没有收到任何答案,那么原因很可能是您没有包含足够的有关问题的信息或没有提供可重复的示例。
-
@Andreas 我更新了标题请帮助解决我的问题
-
.load()调用会覆盖#container3的内容,这会杀死您使用.getElementById()获得的按钮。将.getElementById()调用移动到countDown()函数中 -
@Andreas 先生我做了,但同样的问题显示
标签: javascript html jquery ajax