我已将此功能附加到使用 jquery 的按键事件中,但在 eventObject 中,它为输入的大写和小写字符返回相同的字符代码
function keyPressed(delegates,eventdata){
var keyType = new KeyType();
var keycode = eventdata.which;
if((keycode === 0)&&(eventdata.keyCode === 46)){
keycode=46;
}
switch(keycode)
{
case keyType.enter:
break;
case keyType.backspace:
break;
case keyType.del:
break;
case keyType.space:
break;
default:
keycode = 1;
}
console.log(eventdata.charCode);
console.log(eventdata.which);
console.log(eventdata.keyCode);
//if a delegate is present call it
var delegate = delegates[keycode];
if(delegate !== null){
delegate(eventdata);
}
}