JQuery按照指定長度為數(shù)字前面補零
我們提供的服務有:網(wǎng)站設計制作、網(wǎng)站設計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、黃石ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的黃石網(wǎng)站制作公司
function?PrefixInteger(num,?length)?{ ????return?(Array(length).join('0')?+?num).slice(-length); }
PrefixInteger(8,2);?返回08,表示長度為2,數(shù)字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樣式就需要大家自己去寫了?。?!