JQuery倒計時和按照指定長度為數(shù)字前面補零

JQuery按照指定長度為數(shù)字前面補零

我們提供的服務(wù)有:網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、黃石ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的黃石網(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代碼:
<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樣式就需要大家自己去寫了?。?!JQuery倒計時和按照指定長度為數(shù)字前面補零JQuery倒計時和按照指定長度為數(shù)字前面補零

網(wǎng)頁名稱:JQuery倒計時和按照指定長度為數(shù)字前面補零
文章地址:http://bm7419.com/article8/jcehop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣營銷型網(wǎng)站建設(shè)、網(wǎng)站收錄、服務(wù)器托管、網(wǎng)頁設(shè)計公司、App設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站