我已经尝试了无数解决方案,我在这些论坛上为此找到了解决方案,但没有找到有效的解决方案,或者我只是把它放在了错误的地方。我试图在成千上万的地方强制使用逗号。任何建议和安置将不胜感激。
谢谢。
jQuery(window).scroll(startCounter);
function startCounter() {
var hT = jQuery('.counter').offset().top,
hH = jQuery('.counter').outerHeight(),
wH = jQuery(window).height();
if (jQuery(window).scrollTop() > hT+hH-wH) {
jQuery(window).off("scroll", startCounter);
jQuery('.counter').each(function () {
var $this = jQuery(this);
jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
duration: 4000,
easing: 'swing',
step: function () {
$this.text(Math.ceil(this.Counter));
}
});
});
}
}
最佳答案
假设您想要用逗号分隔值,由 hunders,thousands,millions,...
你可以这样做:
let num = 9876543210;
console.log(num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
// or
console.log((num).toLocaleString());
// or
console.log(new Intl.NumberFormat('en-US', {}).format(num));
关于javascript - 数字脚本之间的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55072574/