javascript - 在 jQuery 中创建一个计时器
问题描述
我需要在jQuery中制作一个计时器,并且在计时器结束(时间= 0)后出现一键,我的问题在哪里?
<style>
.btn_repeat {
display: none;
}
</style>
我的身体
<p>
You'll be automatically redirected in <span id="count">5</span> seconds...
</p>
<button class="btn_repeat">resend</button>
j 查询代码
<script type="text/javascript">
window.onload = function() {
(function() {
var counter = 5;
setInterval(function() {
counter--;
if (counter >= 0) {
span = document.getElementById("count");
span.innerHTML = counter;
}
// Display 'counter' wherever you want to display it.
if (counter === 0) {
clearInterval(counter);
$(".btn_repeat").display = "block";
}
}, 1000);
})();
};
</script>
解决方案
推荐阅读
- c# - . NET 线程被中止异常
- linux - 更新 Certbot 时出现“连接超时(可能是防火墙问题)”
- ios - SwiftUI 自定义相机 - 相机预览不断崩溃
- php - 如何在保存之前在 laravel 作业中调整大小、优化多张图片而不使用第三方服务?
- javascript - 通过 jquery 访问 div 元素数组到 .show() 或 .hide() 每个单独用于轮播
- wordpress - 在 wordpress 中未触发 save_post 操作
- c# - 如何在父游戏对象中找到子游戏对象?
- logstash - 使用logstash编码器流畅->流畅如何将结构化参数传递给Fluentd?
- r - 替换列为 ? 在数据集中
- html - 如何为 Hugo 标签添加颜色