为了账号安全,请及时绑定邮箱和手机立即绑定

JQuery倒计时和按照指定长度为数字前面补零

标签:
JQuery

JQuery按照指定长度为数字前面补零

function PrefixInteger(num, length) {    return (Array(length).join('0') + num).slice(-length);}

PrefixInteger(8,2); 返回08,表示长度为2,数字8前面补一个0。

JQuery倒计时

var rest = 4350859;  //时间戳console.log(rest);$day = Math.floor(rest/(60*60*24));console.log($day);$hour = Math.floor((rest - $day * (60*60*24))/(60*60));console.log($hour);$minite = Math.floor((rest - $day * (60*60*24) - $hour * (60*60))/60);console.log($minite);$second = Math.floor(rest - $day * (60*60*24) - $hour * (60*60) - $minite * 60);console.log($second);$day = PrefixInteger($day,2);$hour = PrefixInteger($hour,2);$minite = PrefixInteger($minite,2);$second = PrefixInteger($second,2);$("#my_day").html($day);$("#my_hour").html($hour);$("#my_minite").html($minite);$("#my_second").html($second);window.setInterval(function(){     rest--;    console.log(rest);    $day = Math.floor(rest/(60*60*24));    console.log($day);    $hour = Math.floor((rest - $day * (60*60*24))/(60*60));    console.log($hour);    $minite = Math.floor((rest - $day * (60*60*24) - $hour * (60*60))/60);    console.log($minite);    $second = Math.floor(rest - $day * (60*60*24) - $hour * (60*60) - $minite * 60);    console.log($second);    $day = PrefixInteger($day,2);    $hour = PrefixInteger($hour,2);    $minite = PrefixInteger($minite,2);    $second = PrefixInteger($second,2);    $("#my_day").html($day);    $("#my_hour").html($hour);    $("#my_minite").html($minite);    $("#my_second").html($second);},1000);
html代码:<ul class="countdown">    <li> <span class="days" id="my_day">00</span>        <p class="days_ref">天</p>    </li>    <li class="seperator">.</li>    <li> <span class="hours" id="my_hour">00</span>        <p class="hours_ref">时</p>    </li>    <li class="seperator">:</li>    <li> <span class="minutes" id="my_minite">00</span>        <p class="minutes_ref">分</p>    </li>    <li class="seperator">:</li>    <li> <span class="seconds" id="my_second">00</span>        <p class="seconds_ref">秒</p>    </li></ul>

这样倒计时功能就完成了,这里css样式就需要大家自己去写了!!!j_0059.gifj_0039.gif


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消