要实现这样
是个财务数的展示问题
例如输入框中有33333,显示为33,333当输入金额的时候,也自动每三个进行分割,还有就是如果直接赋值 例如从数据库查出个数,显示为每三个用,分割 怎么分割 谢谢啦

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>aaa</title></head>
    <body>
    <input id='ss' type="text" onfocus="this.value=this.value.replace(/\,+/g,'');this.select()" onblur="formatnum(this,this.value)" value='1223123123'>
    <script type="text/javascript">
    window.onload = function(){
    var ss  =document.getElementById('ss');
    formatnum.call(ss,ss,ss.value);  //直接赋直就调用下
    }
    function formatnum(o,s){
    o.value = s.replace(/[^\d]+/g,'').replace(reg1,'$1,')
    }
    </script></body>
    </html>
      

  2.   

    上面的正则写掉了  无视吧<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>eee</title></head>
    <body>
    <input id='ss' type="text" onfocus="this.value=this.value.replace(/\,+/g,'');this.select()" onblur="formatnum(this,this.value)" value='12123123123'>
    <script type="text/javascript">
    window.onload = function(){
    var ss  =document.getElementById('ss');
    formatnum.call(ss,ss,ss.value);
    }
    function formatnum(o,s){
    o.value = s.replace(/[^\d]+/g,'').replace(/(\d{1,3})(?=(\d{3})+$)/g,'$1,')
    }</script></body>
    </html>
      

  3.   


    var n = 66666.4;
    alert(n.toLocaleString());
      

  4.   

    不好意思 可能之前我说的不够明白,在HTML的文本框内,显示用“ ,”分割的金额,也就是千分位显示(例如29,897.00元),当点击文本框,每输入一个数字,就自动按照千分位排列, 特殊的情况是当这个数不是整数,有小数位的时候,这个小数点后面的是不需要千分位显示,有几位小数就几位小数,麻烦哪位大侠给做个例子啊 用ASP.net  前台用一个JS方法,后台在做一个,因为有时候这个数我需要从数据库查出来赋值  急急急!!!!!!!
      

  5.   

    var n = 66666.4;
    alert(n.toLocaleString());
      

  6.   

    toLocaleString : String
    Returns a string representing the number that follows local formatting conventions.
    Supported: IE 5.5+, Mozilla 1.0+, Netscape 6.0+, Opera 7.0+, Safari 1.0+