<html> <SCRIPT LANGUAGE="JavaScript"> <!-- function formatNum(obj) { obj.value=obj.value.replace(",",""); if(isNaN(obj.value)) { alert('请填写数字!'); } else { if(obj.value.split(".").length>1)//带小数点的 { var n1=obj.value.split(".")[0]; var n2=obj.value.split(".")[1].substring(0,2); if(n1>3) { var tempStr=""; var arr=new Array(); var j=0; for(i=0;i<n1.length;i+=3) { arr[j] = n1.substring(n1.length-(i+3),n1.length-i);j++ } tempStr = arr.reverse(); obj.value=tempStr+"."+n2; } } else//不带小数点的 { var n1=obj.value; if(n1>3) { var tempStr=""; var arr=new Array(); var j=0; for(i=0;i<n1.length;i+=3) { arr[j] = n1.substring(n1.length-(i+3),n1.length-i);j++ } tempStr = arr.reverse(); obj.value=tempStr; } } } } //--> </SCRIPT> <FORM name=form1 METHOD=POST ACTION=""> <INPUT TYPE="text" NAME="txt1" onblur="formatNum(this);"> </FORM> </body> </html>