JQuery按照指定长度为数字前面补零
我们提供的服务有:网站设计制作、网站设计、微信公众号开发、网站优化、网站认证、黄石ssl等。为上1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的黄石网站制作公司
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代码:
天
时
分
秒
这样倒计时功能就完成了,这里css样式就需要大家自己去写了!!!