第一种:输入整形判断
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 isnumber() {
var ev = getEvent();
if (ev.keyCode == 8) return true; //可删除
if (ev.keyCode < 48 || ev.keyCode > 57) return false;
}
<input id="Text1" name="btntest" type="text" style="IME-MODE: disabled;" οnkeydοwn="return isnumber()" οnpaste="return false" οndragenter="return false"/>
第二种:输入double类型判断
function isnumber(obj) {
if (isNaN(obj.value)) {
obj.value = "";
return false;
}
return true;
}
<input id="Text1" name="btntest" type="text" style="IME-MODE: disabled;" οnkeyup="isnumber(this)" οnpaste="return false" οndragenter="return false"/>