1.给文本框添加一个onkeyup=’clearNoNum(this)’点击事件 
2.建立clearNoNum方法

function clearNoNum(obj) {
obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字而不是
obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数 }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3将金额小写转换成大写

function onlyNumber1(input, n) {
var ret = "";
var number =input.value;
if (number != ""&& number!=null&&number!="0") {
var unit = "仟佰拾亿仟佰拾万仟佰拾元角分",
str = "";
number += "00";
var point = number.indexOf('.');
if (point >= 0) {
number = number.substring(0, point) + number.substr(point + 1, 2);
}
unit = unit.substr(unit.length - number.length);
for (var i = 0; i < number.length; i++) {
str += '零壹贰叁肆伍陆柒捌玖'.charAt(number.charAt(i)) + unit.charAt(i);
}
ret = str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元") + "整";
}
var a = document.getElementsByName("MoneyCapital")[0].id;
document.getElementById(a).value=ret;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
04-25 11:52