1

Possible Duplicate:
handling ctrl + key event in IE browser

I want to use ctrl + key (any number) so that it triggers a javascript event, but if I do that then, the browser changes tab (like it is supposed to do usually).

Is there a way of doing what I would like to do?

4

3 回答 3

2

jquery.hotkeys

https://github.com/jeresig/jquery.hotkeys

Very easy to work with keyboard events.

于 2012-08-09T13:24:25.280 回答
0

In your keydown event handler, use event.preventDefault() :

document.addEventListener("keydown", function(e) {
    if(e.keyCode >= 48 && e.keyCode < 58 && e.ctrlKey == true) {
        e.preventDefault();
    } 
}

This doesn't work in IE8 and below, however, and I can't seem to find a solution that works with attachEvent.

于 2012-08-09T13:25:37.620 回答
0

Shortcut Library (5.66 Kb Standalone)

http://www.openjs.com/scripts/events/keyboard_shortcuts/

shortcut.add("Ctrl+1",function() {
    alert("Hello World!");
});
于 2012-08-09T14:05:56.123 回答