js中的一个只允许数字输入的功能,只要将此功能粘贴在js文件或页面的<script>中即可
function standMoney(inObject){
var inStr = inObject.value;
var i,charValue,outStr,id=0;
for(i=0;i2) {
alert(inStr+" bad money style!");
inObject.focus();
inObject.select();
return;
}
var dotStr,dotValue;
if(valueArr.length==2) {
dotValue = valueArr[1];
if(dotValue.length==0) {
dotStr = "";
}else {
if(dotValue.length==1)
dotStr = dotValue;
else
dotStr = dotValue.substring(0,2);
}
}
var intArr;
intArr = valueArr[0].split(",");
var intValue;
intValue = "";
for(i=0;i1 && intValue.charAt(0)=="0" && intValue.charAt(1)!=".") {
intValue = intValue.substr(1,intValue.length-1);
}
while(intValue.length>3) {
intStr=","+intValue.substring(intValue.length-3,intValue.length) + intStr;
intValue = intValue.substring(0,intValue.length-3);
}
intStr = intValue + intStr;
if(dotStr==null )
outStr = intStr;
else
outStr = intStr + "." + dotStr;
inObject.value = outStr;
return;
}
中国足彩网信息请查看IT技术专栏