<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>document</title>
</head>
<body>
<span id="hour">01</span>
<span>:</span>
<span id="minute">01</span>
<span>:</span>
<span id="second">59</span>
</body>
<script type="text/javascript" src = "../jquery-1.11.0.min.js?1.1.11"></script>
<script type="text/javascript">
var gethour = $('#hour').text();
var getmin = $('#minute').text();
var getsec = $('#second').text();
setinterval(function() {
var alltime = parseint(getsec) + parseint(getmin * 60) + parseint(gethour * 3600);
alltime--;
if (getsec > 0) {
getsec--;
if (getsec < 10) {
getsec = '0' + getsec;
// console.log(getsec)
}
$('#second').html(getsec)
} else {
getsec = 59;
}
if (alltime % 60 == 0) {
getmin--;
// console.log(getmin)
if (getmin >= 0) {
if (getmin < 10) {
getmin = '0' + getmin;
}
$('#minute').html(getmin)
} else {
getmin = 30;
$('#minute').html(getmin)
}
}
if (alltime % 3600 == 0) {
gethour--;
if (gethour >= 0) {
if (gethour < 10) {
gethour = '0' + gethour;
}
$('#hour').html(gethour)
} else {
gethour = 30;
$('#hour').html(gethour)
}
}
}, 1)
</script>
</html>
以上就是js 实现倒计时效果的实例代码分享的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号