키 누르기 (예 : "a"키)의 경우 "a"가 텍스트 입력에 추가되기 전에 keydown
이벤트가 트리거됩니다. 이벤트 유형을 감지하고 .keyCode
(또는 .which
) 이벤트 속성이 인쇄 가능한 범위의 키인지 여부를 확인하고 keyup
이벤트 이후에 반환 할 수있는 내용이 무엇이겠습니까? 이것은 잘못된 아이디어입니다.
this.$input.bind('keydown keyup', function(e) {
var val = this.$input.val();
if (e.type == 'keydown') {
// Here is where you would check to see if e.keyCode was a printable
// character. Note that key codes differ from ASCII codes. For
// example, the "a" key will return key code 65, which is actually
// the ASCII code for "A", so you would need to check for the presence
// of shift keys and such. Again, this is a bad idea :)
val += String.fromCharCode(e.keyCode);
}
if (val == …) { … }
}
입력 상자의 텍스트가 키보드 입력에 즉시 반응하므로 내 위젯의 지연된 응답이 실제로 나타납니다. –
@MatthewRobertson : 업데이트를 참조하십시오. – mpen
와우, 완벽 해 보인다. 너는 모든 것을 얻는다. –