环顾 Stackoverflow,我发现了 this JSFiddle ,但是这个脚本内部似乎有错误,由于我的经验,我不完全理解如何修复。
通过 JSBeautifier 运行,除了以下代码没有缩进之外,所有代码都很好地缩进了;
$.fn.countTo.defaults = {
from: 0, // the number the element should start at
to: 100, // the number the element should end at
speed: 1000, // how long it should take to count between the target numbers
refreshInterval: 100, // how often the element should be updated
decimals: 0, // the number of decimal places to show
onUpdate: null, // callback method for every time the element is updated,
onComplete: null, // callback method for when the element finishes updating
};
})(jQuery);
除此之外,我希望在我的号码中添加逗号,如下所示:
Number(10000).toLocaleString('en'); // "10,000"
1).如何修复某人在 Stackoverflow 上回答、评分并标记为答案的代码,无论是否发现错误?
2). 如何在输出中添加逗号?
最佳答案
这是a version of the jsFiddle插入 addCommas(
) 代码。
它被插入到这一行:
$(_this).html(addCommas(value.toFixed(options.decimals)));
<小时/>
如果你想用它来添加逗号:
Number(10000).toLocaleString('en'); // "10,000"
然后,请确保您希望应用程序运行的所有浏览器版本都支持它。我不能确定,但它可能需要 IE 11。我在 IE9 和 IE10 中尝试了您的方法,似乎当没有要求时添加两位小数。 IE11 按预期工作。
关于javascript - 动态计数器随逗号上升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28710243/