敢于直言批评你的人,定是你命中的贵人

简单的倒计时

js xiaoyun 479℃ 0评论

话不多说,直接看源码吧~

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>倒计时</title>
</head>

<body>
<div class="num"></div>
</body>

</html>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">

seconds = 15;
// console.log(seconds)
$('.num').text(timeStamp(seconds));
timer = setInterval(function() {
seconds--;
// console.log(seconds)
if (seconds <= 0) {
seconds = 0;
clearInterval(timer);
}
$('.num').text(timeStamp(seconds));
}, 1000);
/*秒转时间*/
function timeStamp(second_time) {
var time = parseInt(second_time) + "";
if (parseInt(second_time) > 60) {
var second = parseInt(second_time) % 60;
var min = parseInt(second_time / 60);
second = (second < 10) ? ('0' + second) : second
min = (min < 10) ? ('0' + min) : min
time = min + ":" + second + "";
console.log(min);

if (min > 60) {
min = parseInt(second_time / 60) % 60;
var hour = parseInt(parseInt(second_time / 60) / 60);
second = (second < 10) ? ('0' + second) : second
min = (min < 10) ? ('0' + min) : min
hour = (hour < 10) ? ('0' + hour) : hour
time = hour + ":" + min + ":" + second + "";

if (hour > 24) {
hour = parseInt(parseInt(second_time / 60) / 60) % 24;
var day = parseInt(parseInt(parseInt(second_time / 60) / 60) / 24);
second = (second < 10) ? ('0' + second) : second
min = (min < 10) ? ('0' + min) : min
hour = (hour < 10) ? ('0' + hour) : hour
time = day + ":" + hour + ":" + min + ":" + second + "";
}
}
}else{

time = '00:' +(time<10?'0'+time:time);
}
return time;
}

</script>

转载请注明:小云之家 » 简单的倒计时

喜欢 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址