如何使用jQuery使用逗号增加数字?

我正在尝试在页面上的一个元素内增加一个数字.但是,我需要的数字包括千分之一个值的逗号. (例如45,000不是45000)
<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://jsfiddle.net/4v2wK/

随意更改更多的需要,你也可以看货币格式化,希望这将适合你的需要:)

// Animate the element's value from x to y:
  var $el = $("#el"); //[make sure this is a unique variable name]
  $({someValue: 40000}).animate({someValue: 45000},// can be anything
      step: function() { // called on every step
          // Update the element's text with rounded-up value:
          $el.text(commaSeparateNumber(Math.round(this.someValue)));
      }
  });

 function commaSeparateNumber(val){
    while (/(\d+)(\d{3})/.test(val.toString())){
      val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,");
    }
    return val;
  }

**输出*

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...