1. The best method is still
objevtmap[id+evt]=function (evt,element)
2. Event bind
function Bindevent_4_datablock ()
{
var arr=$ ("#table1 li");
Arr.each (function (index, Element) {
$ (element). KeyPress (function () {
alert (' KeyPress ');
});
var id= "Data_aid_" +index;
$ (Element). attr ("id", "data_aid_" +index);
objevtmap[ID]=function (evt,element)
{
if (evt== "down")
Key_press_hadler ($ (element));
if (evt== "up")
Key_press_hadler4up ($ (element));
if (evt== "left")
{};
if (evt== "RIT")
{}
};}
);
3. Event Dispatch
Document.onkeydown=function (event) {
var e = Event | | window.event | | arguments.callee.caller.arguments[0];
Alert ("KeyCode:" +e.keycode);
if (e && e.keycode==40) {//Under
//alert (' 40 = Next key, 39 = right button ');
var now=$ (". selected");
var id=$ (now). attr ("id");
var func=objevtmap[id];
Func ("Down", now);
Key_press_hadler (now);
return false;
}
Get keyboard events in JS
<script type= "Text/javascript" Language=javascript charset= "utf-" >
document.onkeydown=function (Event) {
var e = Event | | window.event | | arguments.callee.caller.arguments[];
if (e && e.keycode==) {//press ESC
//What to do
}
if (e && e.keycode==) {//press F
//What to do
}
if (e && e.keycode==) {//Enter key
//What to do
}
};
</script>
As long as you define the actions of these keys, you will be able to respond to these keys in your browser, compatible with all browsers currently in the browser.
JS inside the keyboard event is often used, so the keyboard event to collect the corresponding key code to share under:
KeyCode = BackSpace BackSpace keycode = tab Tab keycode = Clear KeyCode = Enter KeyCode = shift_l keycode = control_l key Code = alt_l KeyCode = Pause KeyCode = Caps_lock keycode = Escape escape keycode = Space KeyCode = Prior keycode = Next ke Ycode = End keycode = Home KeyCode = left keycode = up KeyCode = right KeyCode = down KeyCode = Select keycode = Print key Code = Execute KeyCode = Insert KeyCode = Delete KeyCode = Help keycode = equal Braceright keycode = Exclam onesuperior ke Ycode = quotedbl Twosuperior keycode = section Threesuperior keycode = Dollar KeyCode = percent KeyCode = ampersand Keycod E = slash Braceleft keycode = parenleft bracketleft keycode = parenright bracketright keycode = a A keyCode = b b KeyCode = c c KeyCode = d d keycode = e e eurosign keycode = f f keycode = g g keycode = h H keycode = i i keycode = j J KeyCode =
K k keycode = l l keycode = m m mu keycode = n n keycode = o keycode = p p keycode = q q at keycode = r R keycode = s S keycode = t T keycode = u u keycode = v V keycode = w keycode = x x keycode = y y keycode = z z keycode = kp_ kp_ keycode = kp_ kp_ keycode = K P_ KP_
keyCode = KP_ KP_
keyCode = KP_ KP_
keyCode = KP_ KP_
keyCode = KP_ KP_
keyCode = KP_ KP_
keyCode = KP_ KP_
keyCode = Kp_ Kp_ keycode = kp_multiply kp_multiply keycode = kp_add Kp_add keycode = kp_separator kp_separator KeyCode = KP_Subt Ract kp_subtract keycode = kp_decimal kp_decimal keycode = kp_divide Kp_divide keycode = f keycode = f KeyCode = f KeyCode = f KeyCode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode =
F keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f keycode = f KeyCode = Num_lock KeyCode = Scroll_lock keycode = Acute grave keycode = comma semicolon keycode = minus underscore keyCo de = period colon keycode = numbersign apostrophe keycode = plusminus hyphen Macron keycode = keycode = Copyright Register ed keycode = GuillemotleFT guillemotright keycode = masculine ordfeminine keycode = ae ae keycode = cent yen keycode = Questiondown exclamdown key Code = Onequarter onehalf threequarters keycode = less greater bar KeyCode = plus asterisk Asciitilde keycode = multiply D Ivision keycode = Acircumflex Acircumflex keycode = Ecircumflex Ecircumflex keycode = Icircumflex Icircumflex KeyCode = OC Ircumflex Ocircumflex keycode = Ucircumflex Ucircumflex keycode = Ntilde Ntilde keycode = yacute Yacute KeyCode = Oslash O Oblique keycode = aring aring keycode = Ccedilla Ccedilla keycode = Thorn Thorn keycode = eth eth keycode = diaeresis cedi Currency keycode = Agrave Agrave atilde Atilde lla = keycode Egrave egrave = keycode Igrave igrave = KeyCode Ograve otilde Otilde
keyCode = ugrave Ugrave
keyCode = adiaeresis Adiaeresis
keyCode = ediaeresis Ediaeresis
keyCode = idiaeresi s idiaeresis keycode = odiaeresis odiaeresis keycode = udiaeresis udiaeresis keycode = ssharp question backslash KeyCode = Asciicircum degree KEYCOde = Sterling KeyCode = Mode_switch
Use the KeyCode property of the event object to determine the key value entered
Eg:if (event.keycode==) alert ("enter!");
Key value corresponding table
A x U x
B x V x
C x W x
D x x x
E x Y x
F x Z x
G x x
H x x< C8/>i x x
J x x
K x x
L x x
M x x
N x x
O x x
P x x
Q X ESC XB
R X CTRL x
S x SHIFT x
T X ENTER XD
If you want to use a combination of keys, you can determine whether the keys are pressed at the same time, such as CTRL, SHIFT, and the combination of the ALT key to determine whether to press the CTRL key, the SHIFT key, and the ALT key.