<td>
<input id="enjSpAmount" onblur="checkMoney(this)" onkeyup="onlyNumber(this)">
</td>
function onlyNumber(obj){
obj.value = obj.value.replace(/[^\d\.]/g, '');
obj.value = obj.value.replace(/^0\d[0-9]*\.?\d*/g, '');
var vals = obj.value.split(".");
var zsw = vals[0];
var xsw = vals[1];
if (zsw.length > 22) {
zsw = zsw.substring(0, 22);
}
if (xsw) {
if (xsw.length > 2) {
xsw = xsw.substring(0, 2);
}
obj.value = zsw + "." + xsw;
} else {
if (obj.value.indexOf(".") > 0) {
obj.value = zsw + ".";
} else {
obj.value = zsw;
}
}
obj.value = obj.value.replace(/^\./g,'');
obj.value = obj.value.replace(/\.{2,}/g,'.');
obj.value = obj.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
}
function checkMoney(obj) {
var num = obj.value;
if (num == "") {
$.simpleAlert("金额不能为空!");
return false;
} else if (num.substring(num.length - 1) == ".") {
$.simpleAlert("金额不能以.结尾!");
return false;
}
}