Javascript 如何在其中的数字中添加逗号';s 1000到这个计数器脚本
因此,这个脚本的计数等于我添加到跨度中的数字,但我想在11000之后添加一个逗号 如果尝试将Javascript 如何在其中的数字中添加逗号';s 1000到这个计数器脚本,javascript,jquery,number-formatting,Javascript,Jquery,Number Formatting,因此,这个脚本的计数等于我添加到跨度中的数字,但我想在11000之后添加一个逗号 如果尝试将添加到fixed,但没有帮助: $(this.text)(Math.ceil(now.toFixed(3)) $('.counter')。每个(函数(){ $(this.prop('Counter',0)。设置动画({ 计数器:$(this.text()) }, { 持续时间:7000, 放松:"摇摆",, 步骤:功能(现在){ $(this.text(Math.ceil(now)); 停止(); $(
添加到fixed
,但没有帮助:
$(this.text)(Math.ceil(now.toFixed(3))代码>
$('.counter')。每个(函数(){
$(this.prop('Counter',0)。设置动画({
计数器:$(this.text())
}, {
持续时间:7000,
放松:"摇摆",,
步骤:功能(现在){
$(this.text(Math.ceil(now));
停止();
$(this.removeClass('counter');
}
});
});代码>
100
11000
您可以使用toLocalString()
:
$('.counter')。每个(函数(){
$(this.prop('Counter',0)。设置动画({
计数器:$(this.text())
}, {
持续时间:7000,
放松:"摇摆",,
步骤:功能(现在){
$(this.text(Math.ceil(now.toLocaleString());
//这里--------------------^
停止();
$(this.removeClass('counter');
}
});
});代码>
100
11000
您可以使用toLocalString()
:
$('.counter')。每个(函数(){
$(this.prop('Counter',0)。设置动画({
计数器:$(this.text())
}, {
持续时间:7000,
放松:"摇摆",,
步骤:功能(现在){
$(this.text(Math.ceil(now.toLocaleString());
//这里--------------------^
停止();
$(this.removeClass('counter');
}
});
});代码>
100
11000
使用此功能:
$.fn.digits = function(){
return this.each(function(){
$(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
})
}
然后:
$(".count counter").digits();
您也可以使用以下简单代码执行相同操作:
$(this).text(now.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
使用此功能:
$.fn.digits = function(){
return this.each(function(){
$(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
})
}
然后:
$(".count counter").digits();
您也可以使用以下简单代码执行相同操作:
$(this).text(now.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
正是我想要的谢谢正是我想要的谢谢