需求:需要根据②中输入的数字金额自动在①中填入大写金额
代码如下:
{ xtype: "textfield",flex:1.5,id:"num",readOnly: true, allowBlank: false,name: "dxje",
fieldLabel: "本次支付金额"},//①
{ xtype: "numberfield",flex:0.46, allowBlank: false,name: "xxje",
emptyText:"请输入金额"
,enableKeyEvents:true,//启用监听
listeners:{
keyup:function(){
Ext.getCmp('num').setValue(numToCny(this.getValue()));
//给①赋值(使用到了下面的阿拉伯数字转中文大写金额的方法)
}
}
}
以下为阿拉伯数字转中文大写金额的方法:
function numToCny(n){
if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
return "";
var unit = "仟佰拾亿仟佰拾万仟佰拾圆角分", str = "";
n += "00";
var p = n.indexOf('.');
if (p >= 0)
n = n.substring(0, p) + n.substr(p+1, 2);
unit = unit.substr(unit.length - n.length);
for (var i=0; i < n.length; i++)
str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
return str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|圆)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^圆零?|零分/g, "").replace(/圆$/g, "圆整");
}
网友评论