jQuery倒计时 jQuery实现倒计时功能完整示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

jQuery倒计时 jQuery实现倒计时功能完整示例

二萌偏   2021-04-22 我要评论

本文实例讲述了jQuery实现倒计时功能。分享给大家供大家参考,具体如下:

demo代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>www.qb5200.com 时间倒计时</title>
</head>
<body>
<form id="form1" runat="server">
  <div id="show">
  </div>
</form>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
  $(function () {
    TimeDown("show", 3600000)
  });
  /*
   时间倒计时
   TimeDown.js
   */
  function TimeDown(id, value) {
 
    //倒计时的总秒数
    var totalSeconds = parseInt(value / 1000);
 
    //取模(余数)
    var modulo = totalSeconds % (60 * 60 * 24);
    //小时数
    var hours = Math.floor(modulo / (60 * 60));
    modulo = modulo % (60 * 60);
    //分钟
    var minutes = Math.floor(modulo / 60);
    //秒
    var seconds = modulo % 60;
 
    hours = hours.toString().length == 1 ? '0' + hours : hours;
    minutes = minutes.toString().length == 1 ? '0' + minutes : minutes;
    seconds = seconds.toString().length == 1 ? '0' + seconds : seconds;
 
    //输出到页面
    document.getElementById(id).innerHTML = hours + ":" + minutes + ":" + seconds;
    //延迟一秒执行自己
    if(hours == "00" && minutes == "00" && parseInt(seconds)-1<0){
 
    }else{
      setTimeout(function () {
        TimeDown(id, value-1000);
      }, 1000)
    }
 
  }
</script>
</body>
</html>

运行结果:

PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:

在线秒表工具:
http://tools.softyun.net/bianmin/miaobiao

在线日期/天数计算器:
http://tools.softyun.net/jisuanqi/date_jisuanqi

在线日期天数差计算器:
http://tools.softyun.net/jisuanqi/onlinedatejsq

Unix时间戳(timestamp)转换工具:
http://tools.softyun.net/code/unixtime

希望本文所述对大家jQuery程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们