我正在使用服务器端 JS 作为计数器:
var date = new Date(2013,1,01);
var now = new Date();
var number = 0;
var increment = 3290;
var second = 1;
var secondTotal = (now.getTime()-date.getTime())/1000;
var incrementTotal = (secondTotal/1)*3290;
number = Math.round(number+incrementTotal);
function init() {
document.getElementById("kwh_fam_an").innerHTML = number;
setInterval('incrementation()',second*1000);
}
function incrementation() {
number = number+increment;
document.getElementById("kwh_fam_an").innerHTML = number;
}
我试图通过强制每 3 个数字使用一个冒号和一个空格来更改格式,但下面的代码不起作用:
function lisibilite_nombre(nbr) {
var number = '' + nbr;
var retour = '';
var count = 0;
for (var i = number.length - 1; i >= 0 ; i--) {
if (count != 0 && count % 3 == 0)
retour = number[i] + ' ' + retour ;
else
retour = number[i] + retour ;
count++;
}
alert('nb : ' + nbr + ' => ' + retour);
return retour;
}
你有什么主意吗 ?