怎么在JavaScript中利用插件實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)功能?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
1.可以使網(wǎng)頁(yè)具有交互性,例如響應(yīng)用戶點(diǎn)擊,給用戶提供更好的體驗(yàn)。 2.可以處理表單,檢驗(yàn)用戶的輸入,并提供及時(shí)反饋節(jié)省用戶時(shí)間。 3.可以根據(jù)用戶的操作,動(dòng)態(tài)的創(chuàng)建頁(yè)面。 4使用JavaScript可以通過設(shè)置cookie存儲(chǔ)在瀏覽器上的一些臨時(shí)信息。
API
CountDown.openTimeCountBySeconds()
根據(jù)要計(jì)時(shí)的秒數(shù)打開一個(gè)顯示剩余時(shí)間的倒計(jì)時(shí)
參數(shù):
Ele: 放置倒計(jì)時(shí)的元素
CountDownSeconds: 要計(jì)時(shí)的秒數(shù)
Sign: 用于給倒計(jì)時(shí)設(shè)置標(biāo)記 (可以給多個(gè)倒計(jì)時(shí)設(shè)置同一個(gè)標(biāo)記)
Divider: 分割時(shí)分秒的分割符
EndFunc: 倒計(jì)時(shí)結(jié)束時(shí)執(zhí)行的方法
ps:以上均為可選參數(shù)
示例
CountDown.openTimeCountBySeconds({ Ele: document.getElementById('h2'), CountDownSeconds: 3600, Sign: 'flypie', Divider: ':', EndFunc: function () { console.log('end'); } });
CountDown.openTimeCountByStartAndEndDate()
根據(jù)計(jì)時(shí)開始和結(jié)束時(shí)間打開一個(gè)顯示剩余時(shí)間的倒計(jì)時(shí)
參數(shù):
Ele: 放置倒計(jì)時(shí)的元素
StartDate: 倒計(jì)時(shí)開始時(shí)間 (date類型)
EndDate: 倒計(jì)時(shí)結(jié)束時(shí)間 (date類型)
Sign: 用于給倒計(jì)時(shí)設(shè)置標(biāo)記 (可以給多個(gè)倒計(jì)時(shí)設(shè)置同一個(gè)標(biāo)記)
Divider: 分割時(shí)分秒的分割符
EndFunc: 倒計(jì)時(shí)結(jié)束時(shí)執(zhí)行的方法
ps:除StartDate,EndDate外均為可選參數(shù)
示例
var startDate = new Date(); var endDate = new Date(); endDate.setDate(endDate.getDate()+1); CountDown.openTimeCountByStartAndEndDate({ Ele: document.getElementById('h2'), StartDate: startDate, EndDate: endDate, Sign: 'flypie', Divider: ':', EndFunc: function () { console.log('end'); } });
CountDown.openTimeCountByStartAndEndDate()
根據(jù)計(jì)時(shí)開始和結(jié)束時(shí)間打開一個(gè)顯示剩余天數(shù)加時(shí)間的倒計(jì)時(shí)
參數(shù):
Ele: 放置倒計(jì)時(shí)的元素
StartDate: 倒計(jì)時(shí)開始時(shí)間 (date類型)
EndDate: 倒計(jì)時(shí)結(jié)束時(shí)間 (date類型)
Sign: 用于給倒計(jì)時(shí)設(shè)置標(biāo)記 (可以給多個(gè)倒計(jì)時(shí)設(shè)置同一個(gè)標(biāo)記)
Divider: 分割時(shí)分秒的分割符
DateDivider: 天數(shù)和時(shí)間之間的分隔符
EndFunc: 倒計(jì)時(shí)結(jié)束時(shí)執(zhí)行的方法
ps:除StartDate,EndDate外均為可選參數(shù)
示例
var startDate = new Date(); var endDate = new Date(); endDate.setDate(endDate.getDate()+10); CountDown.openDateAndTimeCountByStartAndEndDate({ Ele: document.getElementById('h2'), StartDate: startDate, EndDate: endDate, Sign: 'flypie', Divider: ':', DateDivider: '天 ', EndFunc: function () { console.log('end'); } });
CountDown.stopBySign()
根據(jù)標(biāo)記零時(shí)暫停一個(gè)倒計(jì)時(shí)
CountDown.stopBySign('flypie');
CountDown.resumeBySign()
根據(jù)標(biāo)記恢復(fù)一個(gè)被零時(shí)暫停的倒計(jì)時(shí)
CountDown.resumeBySign('flypie');
CountDown.closeBySign()
根據(jù)標(biāo)記永久性地關(guān)閉一個(gè)倒計(jì)時(shí)
CountDown.closeBySign('flypie');
關(guān)于怎么在JavaScript中利用插件實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)功能問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。