<!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 runat="server"> <title>多个timeout</title> <script src="/Content/js/jquery-1.10.2.min.js" type="text/javascript"></script> </head> <body> <div> <h5 class="text-success">倒计</h5> <p id="order_time_0" data-id="0" endtime="2019-02-02 11:30:59" class="text-success remain-time">a0000</p> <p id="order_time_1" data-id="1" endtime="2019-03-02 11:30:59" class="text-success remain-time">a11111111111</p> <p id="order_time_2" data-id="2" endtime="2019-03-02 12:59:59" class="text-success remain-time">a222222222</p> <p id="order_time_3" data-id="3" endtime="2019-03-03 23:59:59" class="text-success remain-time">a3333333333</p> </div> <script type="text/javascript"> var jsq = { startdata: [], enddata: [], addStart: function (key, value) { if (typeof (jsq.startdata[key]) == 'undefined') { jsq.startdata[key] = value; } }, addEnd: function (key, value) { if (typeof (jsq.enddata[key]) == 'undefined') { jsq.enddata[key] = value; } }, addAll: function () { $(".remain-time").each(function (i) { var key = $(this).data("id"); var startValue = $(this).attr("starttime"); var endValue = $(this).attr("endtime"); //添加计时元素 jsq.addStart(key, startValue); jsq.addEnd(key, endValue); }); //执行检测 jsq.subAll(); }, subAll: function () { for (var index in jsq.startdata) { var nowTime = new Date(); var endTime = new Date(jsq.enddata[index].replace(/-/g, '/')); var timestamp = endTime.getTime() - nowTime.getTime(); //提取时间元素 var _day = Math.floor(timestamp / 1000 / 60 / 60 / 24); var _hour = Math.floor(timestamp / 1000 / 60 / 60 % 24); var _min = Math.floor(timestamp / 1000 / 60 % 60); var _sec = Math.floor(timestamp / 1000 % 60); if (timestamp >= 0) { jsq.startdata[index]--; if (_hour < 10) { _hour = "0" + _hour; } if (_min < 10) { _min = "0" + _min; } if (_sec < 10) { _sec = "0" + _sec; } $('#order_time_' + index).text(_day + "天" + _hour + "时" + _min + "分" + _sec + "秒"); } else { //alert(remainTime); // $("#order_time_" + key).parent().parent().parent().parent().remove(); //删除 } } } }; $(function () { //倒计时 setInterval('jsq.addAll()', 1000); }); </script> </body> </html>
Jquery 一个页面多个倒计时 实现
猜你喜欢
转载自www.cnblogs.com/Fooo/p/10456293.html
今日推荐
周排行