Javascript 添加空格的JS计数器
我有以下代码:Javascript 添加空格的JS计数器,javascript,jquery,counting,Javascript,Jquery,Counting,我有以下代码: function startCounter(){ $('.counter').each(function (index) { $(this).prop('Counter',0).animate({ Counter: $(this).text() }, { duration: 2000, easing: 'swing', step: function (now) { $(this
function startCounter(){
$('.counter').each(function (index) {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 2000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
}
startCounter();
和15000
我想把它和
num.toLocaleString() ;
例如,显示15000而不是15000
我不擅长javascript,所以我不知道怎么做。有人能帮忙吗?您可以创建另一个helper函数,该函数将数字作为输入,并返回本地化字符串。然后您可以用它包装代码的一部分,这将给出实际的数字(
Math.ceil(现在)
)。
阿拉伯语的这两种语言的组合(仅举一个例子)如下所示:
function startCounter(){
$('.counter').each(function (index) {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 2000,
easing: 'swing',
step: function (now) {
$(this).text(toArabic(Math.ceil(now)));
}
});
});
}
function toArabic(x) {
return x.toLocaleString('ar-EG');
}
startCounter();
要获取您的特定国家代码,只需查找“BCP 47语言标签”。
希望我能帮上忙:)好的,在KofferDev的帮助下,我让它工作起来了:
$('.count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 2000,
easing: 'swing',
step: function (now) {
$(this).text(toArabic(Math.ceil(now)));
}
});
});
function toArabic(x) {
return x.toLocaleString('cs-CZ');
}
和HTML部分相同:
15000
这个问题不是很有表现力。在一个更抽象的问题中,你想做什么?在问题中张贴代码,而不是小提琴当它计数时,我想用空格显示更高的数字(10000而不是10000)。$(this).text(现在.tolocalesting('en-US')代码>,检查相应的功能请花几分钟时间阅读并编辑问题,并提供适当详细的问题描述,并将相关代码包含在问题中