gpt4 book ai didi

javascript - 我怎样才能在这个计数器脚本的 1000 中的数字上添加逗号

转载 作者:行者123 更新时间:2023-11-28 13:10:57 26 4
gpt4 key购买 nike

所以这个脚本会计算我添加到范围中的数字,但我想在 11,000 后面添加一个逗号。

如果尝试添加toFixed但这没有帮助: $(this).text(Math.ceil(now).toFixed(3));

$('.counter').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 7000,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now));
stop();
$(this).removeClass('counter');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="number">
<span class="count counter">100</span>
</div>
<div class="number">
<span class="count counter">11000</span>
</div>

最佳答案

您可以使用toLocalString():

$('.counter').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 7000,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now).toLocaleString());
// Here --------------------^
stop();
$(this).removeClass('counter');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="number">
<span class="count counter">100</span>
</div>
<div class="number">
<span class="count counter">11000</span>
</div>

关于javascript - 我怎样才能在这个计数器脚本的 1000 中的数字上添加逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42447477/

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