jquery倒计时功能

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>倒计时测试</title>
<!--<script src="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js" type="text/javascript"></script>-->
<script src="jquery-1.8.0.min.js" type="text/javascript"></script>


<script>
  function lxfEndtime(){
          $(".lxftime").each(function(){
                var lxfday=$(this).attr("lxfday");//用来判断是否显示天数的变量
                var endtime = new Date($(this).attr("endtime")).getTime();//取结束日期(毫秒值)
                var nowtime = new Date().getTime();        //今天的日期(毫秒值)
                var youtime = endtime-nowtime;//还有多久(毫秒值)
                var seconds = youtime/1000;
                var minutes = Math.floor(seconds/60);
                var hours = Math.floor(minutes/60);
                var days = Math.floor(hours/24);
                var CDay= days ;
                var CHour= hours % 24;
                var CMinute= minutes % 60;
                var CSecond= Math.floor(seconds%60);//"%"是取余运算,可以理解为60进一后取余数,然后只要余数。
                if(endtime<=nowtime){
                        $(this).html("已过期")//如果结束日期小于当前日期就提示过期啦
                        }else{
                                if($(this).attr("lxfday")=="no"){
                                        $(this).html("<i>剩余时间:</i><span>"+CHour+"</span>时<span>"+CMinute+"</span>分<span>"+CSecond+"</span>秒");          //输出没有天数的数据
                                        }else{
                        $(this).html("<i>剩余时间:</i><span>"+days+"</span><em>天</em><span>"+CHour+"</span><em>时</em><span>"+CMinute+"</span><em>分</em><span>"+CSecond+"</span><em>秒</em>");          //输出有天数的数据
                                }
                        }
          });
   setTimeout("lxfEndtime()",1000);
  };
$(function(){
      lxfEndtime();
   });
</script>
<style type="text/css">
<!--
*{
        font-style: normal;
        font-weight: normal;}
.haveday {
        padding: 20px;
        border: 1px dashed #000;
        margin-right: auto;
        margin-left: auto;
        width: 300px;
}
-->
</style>
</head>
<body>
<div class="haveday">
<h1>含有天数的倒计时</h1>
<div class="lxftime" endtime="11/15/2011 17:24:0"></div>
<div class="lxftime" endtime="11/8/2011 3:3:20"></div>
<div class="lxftime" endtime="9/6/2015 6:1:0"></div>
<div class="lxftime" endtime="6/6/2016 9:3:5"></div>
</div>
<p></p>
<div class="haveday">
<h1>没有天数的倒计时</h1>
<div class="lxftime" endtime="11/15/2011 17:24:0" lxfday="no"></div>
<div class="lxftime" endtime="11/8/2011 3:3:20" lxfday="no"></div>
<div class="lxftime" endtime="9/6/2015 6:1:0" lxfday="no"></div>
<div class="lxftime" endtime="8/5/2014 16:25:0" lxfday="no"></div>
</div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery遮罩层倒计时可以通过使用jQuery插件和Bootstrap来实现。你可以使用Bootstrap的模态框组件来创建遮罩层,并且使用jQuery的计时器功能来实现倒计时。 首先,你需要在页面中引入jQuery和Bootstrap的相关文件。然后,你可以按照下面的步骤来实现遮罩层倒计时: 1. 创建一个按钮或者其他触发事件的元素,当用户点击该元素时,触发倒计时和遮罩层的显示。 2. 使用jQuery的计时器功能来实现倒计时。你可以使用`setInterval`函数来设置一个定时器,每隔一定的时间更新倒计时的显示内容。 3. 在定时器的回调函数中,更新倒计时的显示内容,并根据剩余时间判断是否显示遮罩层。你可以使用jQuery选择器来获取遮罩层的元素,并使用`show`和`hide`函数来控制其显示和隐藏。 4. 当倒计时结束时,你可以触发弹出模态框(遮罩层)的操作。你可以使用`modal`方法来显示模态框。 这是一个简单的实现示例代码: ```html <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"> </head> <body> <button id="startCountdown" class="btn btn-primary">开始倒计时</button> <div id="myModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">警告</h5> </div> <div class="modal-body"> <p>您的时间已经用完</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-success" data-dismiss="modal">确定</button> </div> </div> </div> </div> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script> <script> $(document).ready(function() { $("#startCountdown").click(function() { var countdown = 10; // 设置倒计时的秒数 var countdownTimer = setInterval(function() { countdown--; if (countdown <= 0) { clearInterval(countdownTimer); $("#myModal").modal("show"); // 显示模态框 } else { $("#countdownDisplay").text(countdown); // 更新倒计时显示 } }, 1000); }); }); </script> </body> </html> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值