日期:2014-05-17 浏览次数:20850 次
<!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></title> <script type="text/javascript"> function Arabic2china(p) { var v = p; var j = {0:'零',1:'壹',2:'贰',3:'叁',4:'肆',5:'伍',6:'陆',7:'柒',8:'捌',9:'玖'}; var d = ['元','拾','佰','仟','万','拾','佰','仟','亿','拾']; var x =['角','分']; var ry = {'零零':'零','零亿':'亿','亿万':'亿','零万':'万','零元':'元'};//,'零角':'','零分':'' var result = ''; var t = v.replace('.',''); if(!/[^\d\.]+/.test(v)&&(v.length-t.length<=1)) { var z = v.split('.'); var l=v,r; if(z.length>1) { l = z[0]; r = z[1]; } if(l.length>10) return '数值太大,不再转换!'; //处理整数部分 for(i=l.length-1;i>=0;i--) { result = j[l.charAt(i)]+((l.charAt(i)=='0'&&(l.length-1-i)%4!=0)?'':d[l.length-1-i])+result; } //处理小数 if(typeof(r) !='undefined') { r = r.substring(0,2); for(i=0;i<r.length;i++) { result += j[r.charAt(i)]+x[i]; } } //替换无效数值 for(n in ry) { while(n=='零零'&&result.indexOf(n)!==-1) { result = result.replace(n,ry[n]); } result = result.replace(n,ry[n]); } }else { result='数值不合法,无法转换!'; } return result; } </script> </head> <body> <input type="text" name="je" id="je" onkeyup="result.innerHTML=Arabic2china(this.value)"/> <div id="result"></div> </body> </html>