我想在页面中的元素内增加一个数字。但是我需要这个数字来包含第千个地方值的逗号。 (例如45,000而不是45000)如何使用jQuery使用逗号来增加数字?
<script>
// Animate the element's value from x to y:
$({someValue: 40000}).animate({someValue: 45000}, {
duration: 3000,
easing:'swing', // can be anything
step: function() { // called on every step
// Update the element's text with rounded-up value:
$('#el').text(Math.round(this.someValue));
}
});
</script>
<div id="el"></div>
如何使用带逗号的动画来增加数字?
看一看这个 http://stackoverflow.com/questions/7327046/jquery-number-formatting – 2013-04-26 02:43:31
我会将数字存储在数据属性中,然后在元素中显示数字的逗号格式化版本。当你增加它时,只需增加数据版本并替换格式化的版本。 – 2013-04-26 02:50:46
这可能对你有帮助 - http://stackoverflow.com/questions/1990512/add-comma-to-numbers-every-three-digits-using-jquery – 2013-04-26 02:50:49