js限制文本框只可以输入数字

封装了一下,要用的话直接调用下面getEvent函数即可
 
 function getEvent() {
if (document.all) {
return window.event; //for ie
}
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
}; function doit(){
var ev = getEvent();
if(ev.keyCode < 8) {return false;}
else if(ev.keyCode > 8 && ev.keyCode < 48) {return false;}
else if(ev.keyCode > 57 && ev.keyCode <96) {return false;}
else if(ev.keyCode > 105) {return false;}
else {return true;}
};
上一篇:Python challenge 3 - urllib & re


下一篇:java中static关键字的作用