怎么在html网页把阿拉伯数字转换成汉字
2个回答
展开全部
用js
<script language="javascript">
function transfer()
{
var input=document.forms[0].elements['xiao'].value;
var danwei=Array("","十","百","千","万","十","百","千","亿");
var inputvalue=parseInt(input);
var l=input.length;
var a=new Array(l);
var b=new Array(l);
var result="";
for(var i=0;i<l;i++)
{
a[i]=input.substr(i,1);
b[i]=getchinese(a[i]);
result+=b[i]+danwei[l-i-1];
}
document.forms[0].elements['da'].value=result;
}
function getchinese(p)
{
var input=p;
if(input=="0")
return "零";
else if(input=="1")
return "壹";
else if(input=="2")
return "贰";
else if(input=="3")
return "叁";
else if(input=="4")
return "肆";
else if(input=="5")
return "伍";
else if(input=="6")
return "陆";
else if(input=="7")
return "柒";
else if(input=="8")
return "捌";
else if(input=="9")
return "玖";
}
</script>
<body>
<form>
<input type="text" name="xiao" /><br>
<input type="button" onclick="transfer()" value="数字转换"/><br>
<input type="text" name="da" readonly="true" size="30" style="border-style:dotted; border-color:#9900FF;"/>
</form>
</body>
<script language="javascript">
function transfer()
{
var input=document.forms[0].elements['xiao'].value;
var danwei=Array("","十","百","千","万","十","百","千","亿");
var inputvalue=parseInt(input);
var l=input.length;
var a=new Array(l);
var b=new Array(l);
var result="";
for(var i=0;i<l;i++)
{
a[i]=input.substr(i,1);
b[i]=getchinese(a[i]);
result+=b[i]+danwei[l-i-1];
}
document.forms[0].elements['da'].value=result;
}
function getchinese(p)
{
var input=p;
if(input=="0")
return "零";
else if(input=="1")
return "壹";
else if(input=="2")
return "贰";
else if(input=="3")
return "叁";
else if(input=="4")
return "肆";
else if(input=="5")
return "伍";
else if(input=="6")
return "陆";
else if(input=="7")
return "柒";
else if(input=="8")
return "捌";
else if(input=="9")
return "玖";
}
</script>
<body>
<form>
<input type="text" name="xiao" /><br>
<input type="button" onclick="transfer()" value="数字转换"/><br>
<input type="text" name="da" readonly="true" size="30" style="border-style:dotted; border-color:#9900FF;"/>
</form>
</body>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询