不熟悉javascript
------解决方案--------------------------------------------------------
function OnlyNum(obj) {
var object = obj;
var reg = /^[0-9]+$/;
var reg2 = /[^0-9]+/;
var val = $(object).val();
if (!reg.test(val)) {
$(object).val(val.replace(reg2, ""));
}
}
<input type="text" onkeyup="OnlyNum(this);"/>
------解决方案--------------------------------------------------------
JQ验证插件