Is it possible to handle such events as:
If it is possible, please give a code example for it.
You can do something like this (jQuery for the click handler, but any framework works on the part that matters):
$(selector).click(function(e) {
if(e.shiftKey) {
//Shift-Click
}
if(e.ctrlKey) {
//Ctrl+Click
}
if(e.altKey) {
//Alt+Click
}
});
Just handle whichever you want inside an if
inside the click handler like I have above.
如果你使用名为热键的 JQuery插件,你可以处理下面的特殊键。
$(document).bind('keydown', 'Ctrl+c', fn);
More recently I encountered a problem with using e.ctrlKey
in that, it does not work on MACs. In a Macintosh, the same effect is achieved using Command+Click.
Since most of the answers above are already assuming usage of jQuery, you can simply use the e.metaKey
property which is made available by jQuery.
eg
$(selector).click(function(e) {
if(e.shiftKey) {
//Shift-Click
}
if(e.metaKey) {
//Ctrl+Click on Windows & Command+Click on Mac.
}
if(e.altKey) {
//Alt+Click
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.