溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發(fā)布時間:2020-07-16 22:59:11 來源:網(wǎng)絡 閱讀:1838 作者:高萬耀 欄目:web開發(fā)

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

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ù)字前面補零


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI