【发布时间】:2020-01-12 21:36:53
【问题描述】:
我是 javascript 菜鸟,毫无疑问。
我的屏幕上有 JQuery CountUp,并浏览了其中一些论坛。计数器在计数时显示一个逗号,但最终数字 (102,050) 仍然没有显示逗号 (102050)
任何指针?这是现在的代码...
$('.counter').each(function() {
const $this = $(this)
const countTo = $this.attr('data-count')
$({ countNum: $this.text()}).animate({ countNum: countTo },
{
duration: 1500,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum).toLocaleString('en'));
},
complete: function (now) {
now = Number(Math.ceil(now)).toLocaleString('en');
$(this).text(now);
$this.text(this.countNum).toLocaleString('en');
}
}
);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="counter" data-count="102050">1</div>
【问题讨论】:
标签: javascript jquery counter