如何实现javascript的数据处理?
以下代码:我想实现打开页面后,在当前页面直接显示数额的小写和大写,应该如何修改下面的代码<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.text.*"%>
<%
Float se=new Float(121.25);
%>
<html>
<head>
<script language="javascript">
function toChinese(num){
var arr1=new Array("元","万","亿");
num=num.toString();
var strRtn="";
if(num.charAt(0)=="-"){
strRtn+="(<b>负</b>)";
num=num.substring(1,num.length);
}
if(num.length>12){ alert("数值超过千亿,无法识别!"); return "数值超过千亿,无法识别!";}
var ss=num.split(".");
var Integer=ss[0];
var Float=ss[1];
var part=splitFour(Integer);
var plen=part.length;
for(var i=0;i<plen;i++){
if(i==0 && plen > 1) strRtn+=ReadFour(part[i],0)+arr1[plen-1-i];
else strRtn+=ReadFour(part[i],1)+arr1[plen-1-i];
}
if(!Float || !checkZero(Float)) {
strRtn+="整"
}else{
strRtn+=AfterPoint(Float);
}
return strRtn;
}
function AfterPoint(num){
var arr1=new Array("角","分");
var arr2=new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
var str="";
for(var i=0;i<num.length;i++){
if(num.charAt(i)!="0")
str+=arr2[num.charAt(i)]+arr1[i];
else{
if(i!=num.length-1) str+="零";
}
}
return str;
}
function splitFour(num){
var len=num.length;
var count=Math.ceil(len/4);
var arr=new Array("");
for(var i=0;i<count;i++){
arr[count-i-1]=num.substring(len-4,len);
len-=4;
}
return arr;
}
function ReadFour(num,iFlag){
var arr1=new Array("","拾","佰","仟");
var arr2=new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
num=num.toString();
var strRtn="";
len=num.length
for(var i=len-1;i>=0;i--){
if(num.charAt(len-i-1)!="0")
strRtn+=arr2[num.charAt(len-i-1)]+arr1[i];
else{
if(iFlag!=0 && strRtn.charAt(strRtn.length-1)!="零" && checkZero(num.substring(len-i,len)))
strRtn+="零";
}
}
return strRtn;
}
function checkZero(str){
for(var i=0;i<str.length;i++)
if(str.charAt(i)!="0") return true;
return false;
}
function format(num){
var tmpVar=Math.round(parseFloat(num,10)*100)/100;
var arr=tmpVar.toString().split(".");
if(arr[1]){
return tmpVar+(arr[1].length==1?"0":"");
}else
return tmpVar+".00";
}
function keyPressFlt(src){
var e=window.event;
code=e.keyCode;
if(code >=48 && code <=57) return true;
else if(code == 46 && src.value.indexOf('.')==-1) return true;
else{ window.event.keyCode=null; return false; }
}
</script>
<style type="text/css">
<!--
.style1 {color: #000000}
.style2 {
color: #FF0000;
font-size: medium;
}
.style3 {color: #FF0000}
-->
</style>
小写金额:<%=se%><br>
大写金额: <%=se_dx%>
</body>
</html>