我正在使用一个脚本来按间隔计数(下面的代码)。
该脚本正在运行,但数字显示为62034。
我希望它显示为62,034。
链接:https://admaxagency.com/app-case-study
我尝试使用此命令:function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
我还尝试添加以下内容:count_2.toLocaleString()
但是它似乎对我不起作用。
谁能告诉我如何使用上面的代码来完成这项工作?
这是我正在使用的javascript:
<b><font face="Raleway" size="50"> Zero to <div id="counter_2" style="display: inline"></div> App Installs with 2.7X ROI</font></b>
<script>
var START_DATE_2 = new Date("August 7, 2019 17:00:00"); // put in the starting date here
var INTERVAL_2 = 0.366; // in seconds
var INCREMENT_2 = 1; // increase per tick
var START_VALUE_2 = 59845; // initial value when it's the start date
var count_2 = 0;
window.onload = function ()
{
var msInterval = INTERVAL_2 * 1000;
var now = new Date();
count_2 = parseInt((now - START_DATE_2)/msInterval) * INCREMENT_2 + START_VALUE_2;
document.getElementById('counter_2').innerHTML = count_2;
setInterval("count_2 += INCREMENT_2; document.getElementById('counter_2').innerHTML = count_2;", msInterval);
}
</script>
<script>
function numberWithCommas(count_2) {
return count_2.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
</script>