嗨,我刚接触jQuery的新手,我遇到了这个脚本
var START_DATE = new Date("July 6, 2015 21:52:00");
var INTERVAL = 20;
var INCREMENT = 1;
var START_VALUE = 9001;
var count = 0;
window.onload = function()
{
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE) / msInterval) * INCREMENT + START_VALUE;
document.getElementById('counter').innerHTML = count;
setInterval("count += INCREMENT; document.getElementById('counter').innerHTML = count;", msInterval);
}
我想将逗号分隔符添加到9001之类的数字中以显示为9,001,请帮助我 问候
答案 0 :(得分:0)
嗨,随着The_Black_Smurf的帮助,我很高兴能够找到我想要的东西。
<script type="text/javascript">
var START_DATE = new Date("July 7, 2015 07:00:00"); // put in the starting date here
var INTERVAL = 20; // in seconds
var INCREMENT = 1; // increase per tick
var START_VALUE = 2824327; // initial value when it's the start date
var count=2824327;
console.log(count.toLocaleString('en-US'))
window.onload = function()
{
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE) / msInterval) * INCREMENT + START_VALUE;
document.getElementById('counter').innerHTML = count.toLocaleString('en-US');
setInterval(function() {
count += INCREMENT;
document.getElementById('counter').innerHTML = count.toLocaleString('en-US');
}, msInterval);
}
</script>
<style>
.death_number{font-size:18px; color:#FFFFFF; background-color:#000000; padding:5px 25px; line-height:20px; font-weight:bold; width:auto; text-align:center;}
</style>
<div id="counter" class="death_number"></div>