我想在頁面中的元素內增加一個數字。但是我需要這個數字來包含第千個地方值的逗號。 (例如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