我一直在爲特定時間和日期(即9am GMT June 17th 2013
)尋找倒數計時器的腳本(最好是JavaScript)。倒計時完成後(即在9am GMT on June 17th
之後),我希望網站自動重定向到另一個頁面。完成後重定向的倒數計時器
回答
其實我寫的,當我們有LAN方與同事:-)
一個簡單的倒計時腳本我沒有花時間,使之成爲jQuery插件,它有一個奇怪的結構,但它的工作原理你可以根據你的需要修改它。
(function($, undefined) {
countdown = function(settings) {
var _this = this,
defaults = {
end: '30.09.2012 09:00'
}, rDate = /(\d+).(\d+).(\d+) (\d+):(\d+)/;
_this.settings = $.extend(defaults, settings);
var matches = _this.settings.end.match(rDate);
_this.endDate = new Date(matches[3], matches[2] - 1, matches[1], matches[4], matches[5], 0, 0);
_this.nDays = $('<span />').addClass('countdown days').html('0');
_this.nHours = $('<span />').addClass('countdown hours').html('0');
_this.nMinutes = $('<span />').addClass('countdown minutes').html('0');
_this.nSeconds = $('<span />').addClass('countdown seconds').html('0');
_this.settings.element.append(
$('<span />').append(
_this.nDays,
' Days'
),
$('<span />').append(
_this.nHours,
' Hours'
),
$('<span />').append(
_this.nMinutes,
' Minutes'
),
$('<span />').append(
_this.nSeconds,
' Seconds'
)
);
countdownMethods.start.call(_this);
return _this;
};
var countdownMethods = {
start: function() {
var _this = this,
interval = 0;
var updateTime = function() {
var now = new Date(),
diff = Math.round((_this.endDate - now)/1000);
if(diff < 0) {
diff = 0;
clearInterval(interval);
window.location.href = 'newurl..';
}
var days = Math.floor(diff/86400);
diff -= days * 86400;
var hours = Math.floor(diff/3600);
diff -= hours * 3600;
var minutes = Math.floor(diff/60);
diff -= minutes * 60;
_this.nDays.html(days);
_this.nHours.html(hours);
_this.nMinutes.html(minutes);
_this.nSeconds.html(diff);
};
updateTime();
interval = setInterval(function() {
updateTime();
}, 1000);
}
};
})(jQuery);
並且你使用這樣的:
$(function() {
var counter = countdown({
end: '08.05.2013 15:15',
element: $('div')
});
});
太棒了!非常感謝!但有一個問題(對不起,我是一個新手),我在哪裏編輯輸入我希望它重定向到倒計時結束時的頁面地址?此次倒計時是否設置爲特定時區? – user2358381 2013-05-07 13:23:57
我原來的倒計時沒有重定向功能。但是如果你看看'updateTime'函數,我添加了一個文本'newurl..',這是URL的地方,你也可以將它作爲一個參數。此倒計時功能僅使用用戶進入頁面的時區。所以,如果你需要解釋這一點,你需要讓你的服務器寫出當前的日期和時間,併爲此編寫腳本帳戶。 – thebreiflabb 2013-05-07 13:38:10
完美無缺,非常感謝thebreiflabb。我非常感謝你的幫助 – user2358381 2013-05-07 13:39:55
- 1. asp:CreateUserWizard完成後重定向
- 2. 重置我的定時器倒計時
- 3. jQuery倒計時和重定向
- 4. iphone定時器倒計時在後臺
- 5. jquery倒計時完成時刪除
- 6. 修復倒計時倒數計時器
- 7. 倒計時 - iPhone倒數計時器
- 8. jquery定時器或倒數計時器
- 9. 倒數計數器/定時器
- 10. 重定向完成
- 11. PHP - 完成流程後重定向PHP
- 12. 如何在Facebook.streamPublish()完成後重定向?
- 13. 倒數計時器
- 14. 倒數計時器
- 15. 倒數計時器
- 16. 倒數計時器?
- 17. WPF定時器倒計時
- 18. jQuery倒計時 - 重置計時器
- 19. 倒數計時器重置日期
- 20. 如何使倒數計時器重複
- 21. 暫停/重置倒數計時器
- 22. 倒數計時器設定點後的數量減少?
- 23. 可定義的倒數計時器
- 24. 到達0後向倒數計時器添加「0」
- 25. 從mysql的倒計時器定時器
- 26. StopCoroutine後重置倒計時時間
- 27. 如何在列表完成計數後操作列表進行倒計時?
- 28. jQuery的倒數計時器
- 29. PHP倒數計時器,當完成7天和重複,直到一定的數量已達到
- 30. 倒計時完成後顯示下載按鈕
你嘗試過什麼?網絡上有很多解決方案可以完成這項簡單的任務。 – Bergi 2013-05-07 13:17:31