时间:2020-10-12 09:32:23 | 栏目:JavaScript代码 | 点击:次
话不多说,直接附上源码,仅供参考
封装了一下,要用的话直接调用下面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;} };