<script>
var START_DATE = new Date("January 01, 2013 00:00:00");
var INTERVAL = 0.25;
var INCREMENT = 0.001;
var START_VALUE = 0;
var count = 0;
function addCommas(str){
var arr,int,dec;
str += '';
arr = str.split('.');
int = arr[0] + '';
dec = arr.length>1?'.'+arr[1]:'';
return int.replace(/(\d)(?=(\d{3})+$)/g,"$1,") + dec;
}window.onload = function(){
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE;
document.getElementById('counter').innerHTML = addCommas(count);
setInterval("count += INCREMENT; document.getElementById('counter').innerHTML = addCommas(count);", msInterval);
}
</script>
<div id="counter"> 30k</div>
我必須把.toFixed(2)放在哪裏,以便我們的非營利組織的餐點只在小數點後兩位顯示。我嘗試了很多不同的地方,但我不確定.toFixed甚至是正確的解決方案。請協助Javascript用餐計數器.toFixed加上逗號
內計數我想這第二個,它是一個卓越和快速的解決方案! – LiQuiD