我想倒計時,並希望顯示格式爲分鐘:秒:毫秒。我用jquery插件countdown倒計時,但它只顯示分鐘:秒的格式。 有什麼方法可以使它正確嗎? 非常感謝!用倒計時顯示毫秒的javascript
0
A
回答
0
嘗試設置格式參數 - http://keith-wood.name/countdownRef.html#format
在進一步閱讀,這個插件不毫秒。此時,您必須編輯實際的插件代碼或找到新的插件。
1
如果你想製作自己的計時器。 閱讀前面的問題
How to create a JQuery Clock/Timer
0
我@馬特球的comment.It完全一致也可能會導致瀏覽器崩潰。
你爲什麼不試試這個方法,而不是
2
嗨,大家好我已經開發了我的自我代碼使用下面的代碼 計數器20秒
var _STOP =0;
var value=1999;
function settimer()
{
var svalue = value.toString();
if(svalue.length == 3)
svalue = '0'+svalue;
else if(svalue.length == 2)
svalue = '00'+svalue;
else if(svalue.length == 1)
svalue = '000'+svalue;
else if(value == 0)
svalue = '0000';
document.getElementById('cn1').innerHTML = svalue[0];
document.getElementById('cn2').innerHTML = svalue[1];
document.getElementById('cn3').innerHTML = svalue[2];
document.getElementById('cn4').innerHTML = svalue[3];
value--;
if (_STOP==0 && value>=0) setTimeout("settimer();", 10);
}
setTimeout("settimer()", 10);
2
試試這個:http://jsfiddle.net/aamir/TaHtz/76/
HTML:
個<div id="timer"></div>
JS:
var el = document.getElementById('timer');
var milliSecondsTime = 10000;
var timer;
el.innerHTML = milliSecondsTime/1000;
timer = setInterval(function(){
milliSecondsTime = milliSecondsTime - 1000;
if(milliSecondsTime/1000 == 0) {
clearTimeout(timer);
el.innerHTML = 'BOOOOM';
}
else {
el.innerHTML = milliSecondsTime/1000;
}
},1000);
0
我做了這樣的(從N個通用計數器X(X> N)):
var dynamicCounterAddNewValue = 20;
var currentDynamicUpdater;
function dynamicCounterForValueForControlUpdater(_updaterData) {
_updaterData.from += dynamicCounterAddNewValue;
if (_updaterData.from > _updaterData.to) {
_updaterData.from = _updaterData.to;
}
_updaterData.c.html(_updaterData.from.toString());
if (_updaterData.from < _updaterData.to) {
currentDynamicUpdater = setTimeout(
dynamicCounterForValueForControlUpdater,
10,
{
c: _updaterData.c,
from: _updaterData.from,
to: _updaterData.to
}
);
}
else {
clearTimeout(currentDynamicUpdater);
}
return;
}
// _c -> jQuery object (div,span)
// _from -> starting number
// _to -> ending number
function dynamicCounterForValueForControl(_c, _from, _to) {
clearTimeout(currentDynamicUpdater);
dynamicCounterForValueForControlUpdater(
{
c: _c,
from: _from,
to: _to
}
);
return;
}
編輯:更新版本(更靈活的 - N個元素一個接一個):
(input ele換貨是使其動態計數元素的數組)
var dynamicCounterTimeout = 10;
var currentDynamicUpdater;
function odcArray(_odca) {
this.odca = _odca;
return;
}
function odc(_c, _from, _to) {
this.c = _c; // $('#control_id')
this.from = _from; // e.g. N
this.to = _to; // e.g. M => (M >= N)
var di = parseInt(_to/45, 10);
if (di < 1) {
di = 1;
}
this.dynamicInc = di;
return;
}
function dynamicCounterForValueForControlUpdater(_odca) {
if (
_odca.odca === null
||
!_odca.odca.length
) {
clearTimeout(currentDynamicUpdater);
return;
}
var o = _odca.odca[0];
o.from += o.dynamicInc;
if (o.from > o.to) {
o.from = o.to;
_odca.odca.shift(); // Remove first element
}
o.c.html(o.from.toString());
currentDynamicUpdater = setTimeout(
dynamicCounterForValueForControlUpdater,
dynamicCounterTimeout,
_odca
);
return;
}
function dynamicCounterForValueForControl(_odca) {
clearTimeout(currentDynamicUpdater);
// SETUP all counters to default
for (var i = 0; i < _odca.odca.length; i++) {
_odca.odca[i].c.html(_odca.odca[i].from.toString());
}
dynamicCounterForValueForControlUpdater(
_odca
);
return;
}
相關問題
- 1. 倒計時秒數:毫秒
- 2. 如何在倒數計時器中顯示毫秒javascript
- 3. NSTimer毫秒倒計時
- 4. 從幾毫秒到幾分鐘秒的JavaScript倒計時腳本
- 5. 如何在倒數計時器標籤中顯示毫秒數?
- 6. 安卓倒計時到毫秒
- 7. 倒計時器跳過一些毫秒
- 8. TimePicker以毫秒爲單位倒計時
- 9. 倒計時如何添加毫秒
- 10. JavaScript倒計時(倒計時)毫秒太快,不會加載下一頁?
- 11. 在計時器中顯示毫秒html
- 12. 如何使用秒和毫秒進行倒計時
- 13. NSTimer倒計時跳過上一秒(不使用最後毫秒)
- 14. iPhone:NSTimer倒計時(顯示分鐘:秒)
- 15. textview不顯示秒數倒計時Android
- 16. Javascript秒數倒計時
- 17. 顯示毫秒
- 18. Javascript以毫秒爲單位顯示毫秒數:小時:無秒數分鐘
- 19. 秒倒計時
- 20. 使用javascript或jquery顯示倒計時
- 21. 以秒,毫秒顯示datediff
- 22. 用毫秒創建倒數計時器(NSTimer),但它不能正確倒計數
- 23. 秒錶/倒計時(00:00:00)用javascript
- 24. 毫秒計時C++
- 25. 用於顯示毫秒
- 26. 顯示倒計時
- 27. Sqllite時間函數顯示的毫秒
- 28. PHP秒倒計時
- 29. 使用秒錶倒計時
- 30. JavaScript倒計時,格式化秒到HH:MM:SS
如果你想顯示倒計時,更新_every單millisecond_,你將開始阻礙瀏覽器的性能。瀏覽器通常不會很快運行`setTimeout` /`setInterval`。但是,嘿 - [請看你自己](http://jsfiddle.net/mattball/q6tQT/)。 – 2011-02-02 04:25:36
你救我很多謝謝! – 2011-02-02 05:21:49