文本框中输入金额的小写,当光标离开的时候,在相应的另一个文本框中显示大写的金额,如何实现
用ASP制作了一个表单,其中在一个文本框中输入金额的小写,当光标离开的时候,在相应的另一个文本框中显示大写的金额,如何实现啊,很急,希望大家告诉我代码!谢谢!...
用ASP制作了一个表单,其中在一个文本框中输入金额的小写,当光标离开的时候,在相应的另一个文本框中显示大写的金额,如何实现啊,很急,希望大家告诉我代码!谢谢!
展开
1个回答
2013-08-02
展开全部
小写变大写可以去找js离开textbox时触发的事件是onblur你可以用下面的例子去完善<input type="textbox" onblur="zhuanhuan(this.value)">然后有个js函数zhuanhuan来进行大小写转换并赋值给另外一个textbox 转换函数你可以用下面的js<SCRIPT LANGUAGE= "JavaScript ">
<!--
function Chinese(num) //将阿拉伯数字翻译成中文的大写数字
{
if(!/^\d*(\.\d*)?$/.test(num)) throw(new Error(-1, "Number is wrong! "));
var AA = new Array( "零 ", "壹 ", "贰 ", "叁 ", "肆 ", "伍 ", "陆 ", "柒 ", "捌 ", "玖 ");
var BB = new Array( " ", "拾 ", "佰 ", "仟 ", "万 ", "亿 ", "圆 ", " ");
var CC = new Array( "角 ", "分 ", "厘 ");
var a = ( " "+ num).replace(/(^0*)/g, " ").split( ". "), k = 0, re = " ";
for(var i=a[0].length-1; i> =0; i--)
{
switch(k)
{
case 0 : re = BB[7] + re; break;
case 4 : if(!new RegExp( "0{4}\\d{ "+ (a[0].length-i-1) + "}$ ").test(a[0]))
re = BB[4] + re; break;
case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
}
if(k%4 == 2 && a[0].charAt(i+2) != 0 && a[0].charAt(i+1) == 0) re = AA[0] + re;
if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;
}
if(a.length> 1) //加上小数部分(如果有小数部分)
{
re += BB[6];
for(var i=0; i <a[1].length; i++)
{
re += AA[a[1].charAt(i)] + CC[i];
if(i==2) break;
}
}
return re;
}
document.write(Chinese( "2345678.6792 "))
//-->
</SCRIPT>
<!--
function Chinese(num) //将阿拉伯数字翻译成中文的大写数字
{
if(!/^\d*(\.\d*)?$/.test(num)) throw(new Error(-1, "Number is wrong! "));
var AA = new Array( "零 ", "壹 ", "贰 ", "叁 ", "肆 ", "伍 ", "陆 ", "柒 ", "捌 ", "玖 ");
var BB = new Array( " ", "拾 ", "佰 ", "仟 ", "万 ", "亿 ", "圆 ", " ");
var CC = new Array( "角 ", "分 ", "厘 ");
var a = ( " "+ num).replace(/(^0*)/g, " ").split( ". "), k = 0, re = " ";
for(var i=a[0].length-1; i> =0; i--)
{
switch(k)
{
case 0 : re = BB[7] + re; break;
case 4 : if(!new RegExp( "0{4}\\d{ "+ (a[0].length-i-1) + "}$ ").test(a[0]))
re = BB[4] + re; break;
case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
}
if(k%4 == 2 && a[0].charAt(i+2) != 0 && a[0].charAt(i+1) == 0) re = AA[0] + re;
if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;
}
if(a.length> 1) //加上小数部分(如果有小数部分)
{
re += BB[6];
for(var i=0; i <a[1].length; i++)
{
re += AA[a[1].charAt(i)] + CC[i];
if(i==2) break;
}
}
return re;
}
document.write(Chinese( "2345678.6792 "))
//-->
</SCRIPT>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询