欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

js 实现倒计时效果的实例代码分享

程序员文章站 2022-04-19 13:47:30
...
<!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 实现倒计时效果的实例代码分享的详细内容,更多请关注其它相关文章!