gpt4 book ai didi

javascript - 在 Javascript Countup 中添加逗号

转载 作者:行者123 更新时间:2023-11-28 17:35:27 27 4
gpt4 key购买 nike

我有这个 JavaScript

<script>
var START_DATE = new Date("February 21, 2018 00:00:00"); // put in the
starting date here
var INTERVAL = 1; // in seconds
var INCREMENT = 6720; // increase per tick
var START_VALUE = 17419171608; // initial value when it's the start date
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);
}
</script>

我试图在上面的代码中用逗号分隔数千个,但我无法这样做。

我尝试了说明 here ,但我无法用逗号分隔数千个。

非常感谢任何帮助。谢谢。

最佳答案

我以你的例子为例并进行了修改。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">

var START_DATE = new Date("December 1, 2010 20:00:00"); // put in the starting date here
var INTERVAL = 1; // in seconds
var INCREMENT = 1; // increase per tick
var START_VALUE = 4166667; // initial value when it's the start date
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 = addCommas(count.toString());
setInterval(incrCount, msInterval);
}

function incrCount() {
count += INCREMENT;
document.getElementById('counter').innerHTML = addCommas(count.toString());
}



function addCommas(nStr){
return parseInt(nStr).toLocaleString();
}
</script>
</head>
<body>

<div id="counter"></div>

</body>
</html>

关于javascript - 在 Javascript Countup 中添加逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49256182/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com