问题
Using jQuery (if it helps), I'd like to create a shortcut key for the letter J, so when someone clicks on the keyboard letter J, it redirects to a webpage.
Is this possible?
回答1:
The short answer is yes, this is possible. See Jquery Events Keypress
If you want it to be a universal shortcut then simply bind
$(document).keypress(function(event) {
if (event.which === 106) { window.location = 'your_url'; }
});
Remember to make it very clear to the users that this will happen. There's nothing more off putting to a user than to accidentally trigger a command they didn't know existed.
回答2:
Based on this page here http://docs.jquery.com/Events/keypress
$().keypress(function (e)
{
//74 == J
//106 == j
if (e.which == 74 || e.which == 106)
{
//redirect
}
});
回答3:
Already asked on SO, read this thread:
Keyboard shortcuts with jQuery
I think, that this answer is what you are looking for (it uses a jQuery plugin):
Keyboard shortcuts with jQuery
来源:https://stackoverflow.com/questions/1580814/creating-a-shortcut-key-for-the-letter-j-to-redirect-to-a-url-using-jquery