js 입력 상자 제어 키보드, 숫자만 쓰고 일부 기능 키 오픈

1538 단어
document.getElementById("userno").onkeydown = function (event) {// 
                var myEvent = new Event(event);
                if (myEvent.key == "enter") {
                    // 
                }
                // , 
                if (myEvent.control == true && (myEvent.code == 67 || myEvent.code == 86 
                    || myEvent.code == 88 || myEvent.code == 115 || myEvent.code == 116)) {
                    if (myEvent.code == 86) {
                        var pstr = "";
                        pstr = window.clipboardData.getData("text");// , IE
                        if (pstr != "" && pstr.match(/^\d+$/) == null) {
                            return false;
                        }
                    }
                    return true;
                }
                // shift , 
                if (myEvent.shift == true && (myEvent.code >= 48 && myEvent.code <= 57)) {
                    return false;
                }
                // , , ,esc,tab,   ,
                //48-57 ,96-105 
                if (!(myEvent.code == 8 || myEvent.code == 9 || myEvent.code == 13 
                || myEvent.code == 16 || myEvent.code == 17 || myEvent.code == 27 
                || myEvent.code == 46 || (myEvent.code >= 48 && myEvent.code <= 57) 
                || (myEvent.code >= 96 && myEvent.code <= 105))) {
                    return false;
                }
            }

좋은 웹페이지 즐겨찾기