JQuery Timers 参数用法参考:http://www.jq22.com/jquery-info148 点击下载:jquery.timers-1.2.js
效果图:
默认数据:
开始计时:
HTML部分代码: <span class="stop stoptime fr">按钮</span> <div class="time-item fr"> <span class="time">倒计时:</span> <strong id="hour_show">116:</strong> <strong id="minute_show">27:</strong> <strong id="second_show">23</strong> </div>
利用来定时制作一个倒计时:
var intDiff = parseInt(60); $(".stop").on("click",function () { if ($(this).hasClass('stoptime')) { $(this).removeClass('stoptime'); //开始倒计时 $('body').everyTime('1s',"time-item",function () { var day=0, hour=0, minute=0, second=0;//时间默认值 if(intDiff > 0){ day = Math.floor(intDiff / (60 * 60 * 24)); hour = Math.floor(intDiff / (60 * 60)) - (day * 24); minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60); second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60); } if (minute <= 9) minute = '0' + minute; if (second <= 9) second = '0' + second; $('#day_show').html(day+"天"); $('#hour_show').html('<s id="h"></s>'+hour+':'); $('#minute_show').html('<s></s>'+minute+':'); $('#second_show').html('<s></s>'+second); intDiff--; if (intDiff == 0) { alert('考试结束,赶紧交卷...'); } }); } else { //暂停倒计时 $(this).addClass('stoptime'); $('body').stopTime("time-item"); } })