问题
I want to disable print for some webpages. How to wireup cross browser hotkeys (Cntrl + P) to a javascript that will be fired whenever hotkeys are pressed?
回答1:
You can override by capturing the event.
jQuery(document).bind("keyup keydown", function(e){
if(e.ctrlKey && e.keyCode == 80){
return false;
}
});
回答2:
Also a great library is Mousetrap
回答3:
Try Keyboard Shortcuts Library.
Instead of just copy pasting it let's havea look at the source and understand how it works.
You can see the source here
来源:https://stackoverflow.com/questions/12517819/how-to-listen-for-ctrl-p-key-press-in-javascript