<!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>
  <title> new document </title>
  <meta name="generator" content="editplus" />
<script type="text/javascript">
<!--
function commafy(oInput){
var re=/(-?\d+)(\d{3})/
var num = oInput.value;
while(re.test(num)){
num=num.replace(re,"$1,$2")
}
oInput.value=num
}//-->
</script>
 </head> <body>
 <input type="text" id="entry"  size=20  onblur="commafy(this)"> 
 </body>
</html>

解决方案 »

  1.   

    不好意思,倒是可以了,但有个问题,这个在修改时,修改后的不能格式化,
    能不能在输入时,也就是textchange时就自动转化
      

  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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
    <script type="text/javascript">
    <!--    
        function commafy(oInput){
        var re=/(-?\d+)(\d{3})/
        var num = oInput.value.replace(/,/g,"");
        while(re.test(num)){
                num=num.replace(re,"$1,$2")
            }
            oInput.value=num
        }//-->
    </script>
     </head> <body>
     <input type="text" id="entry"  size=20  onkeyup="commafy(this)"> 
     </body>
    </html>