<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script type="text/javascript"> function change(num) { if(!/^[-+]?([0-9]+)([.]?[0-9]*)([eE]?[1-9]*)$/.test(num)){alert( "请输入阿拉伯数字!");num="";} var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); var BBB = new Array("圆","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟"); var CC = new Array("角","分","厘","钱","毫"); var strnum=num; if(strnum.indexOf(".")>0) { var strzs=strnum.slice(0,strnum.indexOf(".")); var strxs=strnum.slice(strnum.indexOf(".")+1,strnum.length); } else { var strzs=strnum; var strxs=""; } if(strzs.length>12){alert("你输入的金额超过了仟亿!请重新输入!"); strzs="";} var bb=new Array(); var dd=new Array(); var tt=new Array(); d=""; f=""; x="啊"; //整数部分 for (i=strzs.length-1;i>=0;i--) { bb[i]=strzs.slice(i,i+1); switch(bb[i]) { case "0" : bb[i]=AA[0];break; case "1" : bb[i]=AA[1];break; case "2" : bb[i]=AA[2];break; case "3" : bb[i]=AA[3];break; case "4" : bb[i]=AA[4];break; case "5" : bb[i]=AA[5];break; case "6" : bb[i]=AA[6];break; case "7" : bb[i]=AA[7];break; case "8" : bb[i]=AA[8];break; case "9" : bb[i]=AA[9];break; } bb[i]=bb[i]+BBB[strzs.length-i-1]; d=bb[i]+d; } for(i=0;i<=d.length;i++) { if(d.slice(i,i+1)!="零") {} else { if(d.slice(i+1,i+2)=="萬" || d.slice(i+1,i+2)=="億" || d.slice(i+1,i+2)=="圆") {d=d.slice(0,i)+x+d.slice(i+1);} else if(i+3<d.length && d.slice(i+2,i+3)=="零") {d=d.slice(0,i)+x+x+d.slice(i+2);} else {d=d.slice(0,i+1)+x+d.slice(i+2);} } } d=d.replace(/啊/g,"") if(d.indexOf("億萬")>0) {d=d.replace(/萬/g,"")} //alert(d); //小数部分 for(i=0;i<strxs.length && i<5;i++) { dd[i]=strxs.slice(i,i+1); switch(dd[i]) { case "0" : dd[i]=AA[0];break; case "1" : dd[i]=AA[1];break; case "2" : dd[i]=AA[2];break; case "3" : dd[i]=AA[3];break; case "4" : dd[i]=AA[4];break; case "5" : dd[i]=AA[5];break; case "6" : dd[i]=AA[6];break; case "7" : dd[i]=AA[7];break; case "8" : dd[i]=AA[8];break; case "9" : dd[i]=AA[9];break; } f=f+dd[i]+CC[i]; } for(i=0;i<=f.length;i++) { if(f.slice(i,i+1)!="零") {} else { if(i+3<=10 && f.slice(i+2,i+3)=="零") {f=f.slice(0,i)+x+x+f.slice(i+2);} else {f=f.slice(0,i+1)+x+f.slice(i+2);} } } f=f.replace(/啊/g,"") dxnum=d+f; if(strxs==""&&num!="") { dxnum=d+"整"; } //alert(dxnum); if(dxnum.slice(0,i)=="零") {dxnum=dxnum.slice(i);} if(dxnum.slice(dxnum.length-1)=="零") {dxnum=dxnum.slice(0,dxnum.length-1);} if(dxnum.indexOf("億")==0) {dxnum=dxnum.replace(/億/i,"")} if(dxnum.indexOf("萬")==0) {dxnum=dxnum.replace(/萬/i,"")} if(dxnum.slice(0,i)=="零") {dxnum=dxnum.slice(i);} //结果 return(dxnum); } function bian() { document.all.form1.textfield2.value=change(document.all.form1.textfield.value); } </script> </head> <body > <form id="form1" name="form1" method="post" action=""> <p> 最大转化金额:<input type="text" name="zuida" value="999999999999.99999" disabled="disabled"> </p> <p> <input type="text" name="textfield" style="width:150px;" onblur="bian();" /> </p> <p> <input type="button" value="转变为大写" onclick="bian();" /> </p> <p> <input type="text" name="textfield2" style="width:500px;" /> </p> </form> </body> </html>