Localising key combination detection to specific active parts of DOM
I need to detect keystroke c开发者_JAVA技巧ombinations in one active (focused) element. However when I have focus on another element and the same keystrokes are pressed, the action shouldn't be fired.
I seem to have trouble doing this. Any help will be appreciated.
Thanks.
You could check out my jQuery plugin that would allow you to do this by selecting the element then picking the key like:
$('input').jkey('alt+a',function(){
console.log('You pressed alt+a!');
})
Docs: http://oscargodson.com/labs/jkey/
Source: https://github.com/oscargodson/jkey
精彩评论